1、 仅easyui代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/ztree3.5/zTreeStyle.css" type="text/css">
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/ztree3.5/jquery.ztree.all-3.5.js"></script>
</head>
<body >
<input class="easyui-combobox" id="language" name="language"
data-options="valueField:'id',textField:'text',url:'${pageContext.request.contextPath}/demo/combobox_data1.json'" >
</body>
</html>
2、easyui+java
jsp:
<tr> <td>选择区域</td> <td> <input class="easyui-combobox" name="region.id" data-options="valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/region_selectregion.action'" /> </td> </tr>
action:
public void selectregion() throws IOException { List<Region> regionList=iRegionService.findAll(); RespJson(regionList,new String[]{}); //基类方法 }
基类:
protected void RespJson(Object o, String[] strs) throws IOException {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(strs);
HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
httpServletResponse.setHeader("content-type", "text/json;charset=utf-8");
if(o instanceof Collection){ //是否是集合
JSONArray jsonObject=JSONArray.fromObject(o, jsonConfig);
httpServletResponse.getWriter().write(jsonObject.toString());
}else{
JSONObject jsonObject = JSONObject.fromObject(o, jsonConfig);
httpServletResponse.getWriter().write(jsonObject.toString());
}
}
在Region中无name属性,新加入getName方法,json中的标题字段,仅仅是get方法中的字段
package com.dong.bos.model;
import java.util.Objects;
public class Region {
private String id;
private String province;
private String city;
private String district;
private String postcode;
private String shortcode;
private String citycode;
public String getName() {
return province+city+district;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
public String getShortcode() {
return shortcode;
}
public void setShortcode(String shortcode) {
this.shortcode = shortcode;
}
public String getCitycode() {
return citycode;
}
public void setCitycode(String citycode) {
this.citycode = citycode;
}
public Region() {
}
public Region(String id, String province, String city, String district, String postcode, String shortcode, String citycode) {
this.id = id;
this.province = province;
this.city = city;
this.district = district;
this.postcode = postcode;
this.shortcode = shortcode;
this.citycode = citycode;
}
@Override
public String toString() {
return "Region{" +
"id='" + id + '\'' +
", province='" + province + '\'' +
", city='" + city + '\'' +
", district='" + district + '\'' +
", postcode='" + postcode + '\'' +
", shortcode='" + shortcode + '\'' +
", citycode='" + citycode + '\'' +
'}';
}
}