html - Get JSON Multidimensional Array Keys - AngularJS -
i trying build form out of json array. need load keys html. here example of array:
{   "fred": {      "description": "a dude"   },   "tomas": {      "description": "another dude",      "work": {        "current": "no employer",        "previous": "enron"      }   } }   what values fred & thomas. when run in angular html:
<div ng-repeat="set in sets">   <p ng-repeat="(key, val) in set">     <span ng-bind="key"></span>: <span ng-bind="val"></span>   </p> </div>   i error "ngrepeat-dupes" although fred , tomas not duplicate values. appreciated.
you getting dupe error key being same in both objects. can fix using track $index, in data have provided, there no dupes... see fiddle - https://jsfiddle.net/t4q4nrfp/36/
if did have dupes in data though add in track $index (you can use other things index default) :
<div ng-repeat="set in sets track $index"> << add here if have dupes level     <p ng-repeat="(key, val) in set track $index"> << or here if dupes @ level       <span ng-bind="key"></span>: {{val}} <span ng-bind="val"></span>     </p> </div>   also, clear, working object not array.
Comments
Post a Comment