$("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").autocomplete("/web/commonController.do?getAutoList",
{ max: 5,
minChars: 1,
width: 200,
scrollHeight: 100,
matchContains: true,
autoFill: false,
extraParams:
{featureClass : "P",
style : "full",
maxRows : 10,
labelField : "id,renyuanXm,renyuanDwmc",
valueField : "renyuanXm",
searchField : "renyuanXm",
entityName : "RyEntity",
trem: getTremValuexljhxxSpr
},
parse:function(data){
var parsed = [];
$.each(data.rows,function(index,row){
parsed.push({data:row,result:row,value:row.id});
});
return parsed;
//return defineFunc.parse.call(this,data);
},
formatItem:function(row, i, max){
return row.renyuanXm + "-->" + " " + row.renyuanDwmc;
}
}).result(function (event, row, formatted) {
$("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").val(row.renyuanXm);
});
function getTremValuexljhxxSpr()
{
return $("#xljhxx_spr_3DE927CE6EE8366E122E3D3A652D5647").val();
}
对应的action方法:
/**
* 自动完成请求返回数据
*
* @param request
* @param responss
*/
@RequestMapping(params = "getAutoList")
public void getAutoList(HttpServletRequest request, HttpServletResponse response, Autocomplete autocomplete) {
String jsonp = request.getParameter("jsonpcallback");
String trem = StringUtil.getEncodePra(request.getParameter("trem"));// 重新解析参数
System.out.println(trem);
autocomplete.setTrem(trem);
List autoList = systemService.getAutoList(autocomplete);
String labelFields = autocomplete.getLabelField();
String[] fieldArr = labelFields.split(",");
String valueField = autocomplete.getValueField();
String[] allFieldArr = null;
if (StringUtil.isNotEmpty(valueField)) {
allFieldArr = new String[fieldArr.length+1];
for (int i=0; i<fieldArr.length; i++) {
allFieldArr[i] = fieldArr[i];
}
allFieldArr[fieldArr.length] = valueField;
}
try {
String str = TagUtil.getAutoList(autocomplete, autoList);
str = "(" + str + ")";
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.getWriter().write(JSONHelper.listtojson(allFieldArr,allFieldArr.length,autoList));
response.getWriter().flush();
response.getWriter().close();
} catch (Exception e1) {
e1.printStackTrace();
logger.error(e1);
}
}
转载于:https://my.oschina.net/u/2552902/blog/543960