javascript - How to extract data from a json object which contains a map with different kinds of objects -


i return json server jsonified map object java. map has list , integer. how can list in jquery?

int found = hits.length;  list<object> results = new arraylist<object>();  (scoredoc scoredoc : hits) {      ....      // create object , add 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); 

i pull results search ajax:

function  search(query){     $.ajax({         type: 'post',         url: 'search',         data: query,         success: function(data){             showresults(data);         },         datatype: 'json'     }); } 

now in show results dont know how list map. appreciated

function showresults(data){     if(!$('#livesearchcontainer').is(':visible')){         $(this).show(2000);     } } 

some facts javascript , jquery

  • jquery should parse data json string javascript objects.
  • all javascript objects hash maps
  • you can access javascript object properties doing object.someproperty or object["someproperty"]
  • if unsure has been passed function, console.log(arguments)

answer:

in function showresults:

var results = data.results // hash lookups quick reason // cache result have less type! 

then like

$('#livesearchcontainer').html('<p>'+data.hits+' hits</p><ol></ol>');  results.foreach(function(result) {   $('#livesearchcontainer ol').append(buildresulthtml(result)); })  // might write buildresulthtml build html search result 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -