按照jquery中的实例做的,jsp页面中的javascript上:$().ready(function() {
$("#home_address").autocomplete('getJdtype.do', {
minChars: 0,
width: 310,
matchContains: true,
autoFill: false,
formatItem: function(row, i, max) {
return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
},
formatMatch: function(row, i, max) {
return row.name + " " + row.to;
},
formatResult: function(row) {
return row.to;
}
});
} 控制器中:public void getJdtype(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String parent = request.getParameter("q");
//int count=0;
String str = "";
List<Map> list;
if(StringUtils.isBlank(parent)){
//count=0;
//str=String.valueOf(count);
return;
}else{
list = getTDkindByTG(Integer.valueOf(parent));
//count=list.size();
//str=String.valueOf(count);
for(Map map :list){
String name=String.valueOf(map.get("kindremark"));
String id=String.valueOf(map.get("acceptdkindid"));
str += "{ name: \""+name+"\", to: \""+id+"\" },\n";
}
}
str = "[" + str + "]";
System.out.println(str);
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(str);
} 页面显示部分,总是提示“undefined”
我在页面中直接调试http://localhost:8088/project/getJdtype.do?q=4
显示的内容为:
[{ name: "催促揽", to: "13" }, { name: "催送发票(底单)", to: "38" }, { name: "催送单", to: "39" }, { name: "(底单)", to: "43" }, ]
是不是要显示成数组形式,而不是字符串呢,但动态数组不知道各位是如何实现的。盼。。。。。。 |