我正在尝试使用 JQuery 和 Spring 2.5.6 显示自动完成列表,但我正在将 json 发送到前端,但我无法显示它。
$(function() {
$("#globalSearch").autocomplete({
source: function(request, response) {
$.ajax({
url: "${pageContext.request.contextPath}/autoSearch.htm",
data: {
term : request.term
},
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
// this is the alert output its displaying:{"list":["ernst","ernst "]}
alert(JSON.stringify(data, null, 4));
response($.map(data, function(item) {
//its not alerting anything here
alert(JSON.stringify(item, null, 4));
return{
value: item.list
};
}));
}
});
}
});
});
这是我的弹簧控制器代码:
@RequestMapping(method = RequestMethod.GET, value = "/autoSearch.htm")
public ModelAndView autoSearch(
@RequestParam(value = "term", required = false) String term
) throws ParseException, IOException {
if (logger.isDebugEnabled()) {
logger.debug("inventoryHandler called");
}
Map<String, Object> model = new HashMap<String, Object>();
int i = 0;
model.put("list", getBaseModel().getSearchServiceBean().autoCompleter(term));
return new ModelAndView("jsonView", model);
}
谁能告诉我如何显示自动完成列表。
提前致谢,
最好的问候,拉贾。