JQuery EasyUI combobox动态添加option
<input class="easyui-combobox" id="rwlb" name="rwlb" style="width:435px" data-options="valueField:'id', textField:'text', panelHeight:'auto'" >
方法一:
var data, json;
json = '[{"id":"年计划","text":"年计划","selected":true}]';
data = $.parseJSON(json);
$("#rwlb").combobox("loadData", data);
方法二:
var data,json;
data = [];
data.push({ "text": "测试", "id": 100 });
$("#rwlb").combobox("loadData", data);
方法三:
$("#templetGroupID").combobox({
data: $.parseJSON('[{"id":"0","text":"无选项","selected":true}]'),
editable: false, //不可编辑状态
cache: false,
valueField: 'id',
textField: 'text',
panelHeight: 'auto'
});
动态:
@RequestMapping("/getsite")
@ResponseBody
public String getSite() {
List<BaseBean> list = null;
try {
String userID = request.getParameter("userID");
System.out.println("--userID--" + userID);
list = iSiteService.getByHQL("from SiteBean");
} catch (Exception e) {
e.printStackTrace();
}
if (list.size() > 0) {
StringBuffer site = new StringBuffer();
site.append("[");
for (int i = 0; i < list.size(); i++) {
SiteBean siteBean = (SiteBean) list.get(i);
if (i == 0) {
site.append("{\"id\":\"" + siteBean.getSiteID() + "\",\"text\":\"" + siteBean.getSiteName() + "\",\"selected\":\"" + true + "\"}");
} else {
site.append(",{\"id\":\"" + siteBean.getSiteID() + "\",\"text\":\"" + siteBean.getSiteName() + "\"}");
}
}
site.append("]");
return site.toString();
} else {
return "[{\"id\":\"\",\"text\":\"无可用选项\",\"selected\":\"" + true + "\"}]";
}
}