Iterating JSON using Jquery -


i want iterate , return array jquery autocomplete.can please suggest me how return result term raj , rajesh in array autocomplete functionality.

{     "responseheader": {         "status": 0,         "qtime": 21     },     "command": "build",     "suggest": {         "mysuggester": {             "r": {                 "numfound": 2,                 "suggestions": [                     {                         "term": "raj",                         "weight": 0,                         "payload": ""                     },                     {                         "term": "rajesh",                         "weight": 0,                         "payload": ""                     }                 ]             }         }     } } 

you can use code below , feed resulting autocomplete_data jquery autocomplete:

var data = { "responseheader": { "status": 0, "qtime": 21 }, "command": "build", "suggest": { "mysuggester": { "r": { "numfound": 2, "suggestions": [{ "term": "raj", "weight": 0, "payload": "" }, { "term": "rajesh", "weight": 0, "payload": "" }] } } } };  var parentnode = data.suggest.mysuggester; var suggestionsnode = null; (var key in parentnode) {     suggestionsnode = parentnode[key].suggestions;     if(suggestionsnode!=null)         break; }  var autocomplete_data = []; $.each(suggestionsnode, function (i, val) {     autocomplete_data.push(val.term); }); console.log(autocomplete_data); $("#autocomplete-container").autocomplete({     source: autocomplete_data     }); 

jsfiddle link


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -