后台
@RequestMapping(value = "/getCompany", method = RequestMethod.POST) @ResponseBody public JSONArray getCompany(String q) { List<EnterpriseInfo> enterpriseInfos = orderService.getEnterpriseByName(q); if(CollectionUtils.isNotEmpty(enterpriseInfos)){ JSONArray jsonArray = JSONArray.fromObject(enterpriseInfos); return jsonArray; }else{ return null; } }
前端js
$(function () { $('#companyId').combobox({ prompt:'输入关键字后自动搜索', required:true, mode:'remote', url:'/order/getCompany', editable:true, hasDownArrow:false, valueField: "enterpriseId", textField: "enterpriseName", onBeforeLoad: function(param){ console.log("--------------"+param.q); if(param == null || param.q == null || param.q.replace(/ /g, '') == ''){ var value = $(this).combobox('getValue'); if(value){// 修改的时候才会出现q为空而value不为空 param.id = value; return true; } return false; } } }); });
前端html <input id="companyId" class="easyui-combobox" name="companyId" style="width:270px;" data-options="editable:false,valueField:'id', textField:'text'" />