我从服务器返回JSON,该服务器是来自java的JSONified Map对象。 Map有一个列表和一个整数。如何在jquery中获取列表?
int found = hits.length;
List<Object> results = new ArrayList<Object>();
for (ScoreDoc scoreDoc : hits) {
....
// create an object and add to results list
results.add(Object)
}
Map map = new HashMap();
map.put("results", results);
map.put("hits", found);
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(map);
我通过ajax搜索结果:
function search(query){
$.ajax({
type: 'POST',
url: 'search',
data: query,
success: function(data){
showResults(data);
},
dataType: 'json'
});
}
现在在节目结果中,我不知道如何从地图中获取我的列表。任何帮助将不胜感激
function showResults(data){
if(!$('#liveSearchContainer').is(':visible')){
$(this).show(2000);
}
}
答案 0 :(得分:0)
关于javascript和JQuery的一些事实
object.someProperty
或object["someProperty"]
console.log(arguments)
答案:
功能showResults
中的:
var results = data.results
// Hash lookups are so quick that the only reason
// we cache the result is so we have less to type!
然后像
$('#liveSearchContainer').html('<p>'+data.hits+' hits</p><ol></ol>');
results.forEach(function(result) {
$('#liveSearchContainer ol').append(buildResultHTML(result));
})
// Where you might write buildResultHTML to build HTML for a search result