angularjs - Iterate through multi dimensional arrays that contain objects -


can iterate through json response es (v1.5) angularjs foreach?

{response:[property: value,property: value, hits:{property: value, property: value}, hits: [{property:value,property:value, {property:value}}], hits:[{property:value,property:value, {property:value}}]]} 

as can see response [] has 2 hits arrays, both hits arrays full of objects. trying iterate through them using angular.foreach ... not having luck

do need break each hits array down , run through own foreach?

var multi_match_results = es_return.responses[0].hits.hits; angular.foreach(multi_match_results), function(value, key) { ... }   var mlt_results = es_return.responses[1].hits.hits; angular.foreach(mlt_results), function(value, key) { ... } 

or

is there way iterate through these nested foreach? if so, example code great!

update

here small sample of actual data returned es

    {    "responses": [       {          "took": 38,          "timed_out": false,          "_shards": {             "total": 1,             "successful": 1,             "failed": 0          },          "hits": {             "total": 6,             "max_score": 2.8937743,             "hits": [                {                   "_index": "query-index1",                   "_type": "autocomplete",                   "_id": "avho-9ifp_gdq4wcr69k",                   "_score": 2.8937743,                   "_source": {                      "suggestions": "term term"                   }                },                {                   "_index": "query-index1",                   "_type": "autocomplete",                   "_id": "avho-9ifp_gdq4wcr69l",                   "_score": 2.8937743,                   "_source": {                      "suggestions": "term1 term1"                   }                }             ]          }       },       {          "took": 51,          "timed_out": false,          "_shards": {             "total": 1,             "successful": 1,             "failed": 0          },          "hits": {             "total": 317,             "max_score": 3.055048,             "hits": [                {... 

so can see in return object there responses array, contains 2 separate hits arrays , hits arrays contains objects hold data 2 queries.

my search() returns results so

return searchservice.search(vm.searchterms, vm.currentpage).then(function(es_return) {     var results = es_return.responses;     var totalitems = es_return.responses[0].hits.total;     var totaltime = es_return.responses[0].took;     var numpages = math.ceil(es_return.responses[0].hits.total / vm.itemsperpage);     vm.results.pagination = [];     (var = 0; < results.length; i++) {       console.log(results);       (var j = 0; j < results.length; j++) {         console.log(results);       vm.results.totalitems = totalitems;       console.log(vm.results.totalitems);       vm.results.querytime = totaltime;       vm.results.pagination = searchservice.formatresults(es_return.responses[0].hits.hits);//load first 100 results       vm.results.documents = vm.results.pagination.slice(vm.currentpage, vm.itemsperpage);       console.log(vm.results.documents);       vm.results.mlt = es_return.responses[1].hits.hits;       }     } 

the 2 loops see not right tool job. suggestions?

it looks json have not valid json have duplicate keys. might want reconsider way generating json values.

here post on similar lines :

https://stackoverflow.com/a/38267020/6794233

and happens iterations, when have duplicates keys here.

https://stackoverflow.com/a/5306792/6794233

var responseobj = {    response: [property: value, property: value, hits: {        property: value,        property: value      },      hits: [{        property: value,        property: value,        {          property: value        }      }],      hits: [{        property: value,        property: value,        {          property: value        }      }]    ]  };


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -