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 });
Comments
Post a Comment