ng-repeat over array of objects vs. object containing objects

倖福魔咒の 提交于 2020-01-03 06:40:12

问题


In almost all the examples of ng-repeat I've seen, the data is structured like so:

$scope.dataCollected = [{name: bob, data: '10-12-12'}, {name:joe, data: '09-13-13'}];

However, the only way I can get ng-repeat to work is if I structure the data like this:

$scope.dataCollected = {bob: {name: bob, data: '10-12-12'}, joe: {name:joe, data: '09-13-13'}};

Structuring it as an array causes the ng-repeat to do absolutely nothing. It doesn't even give an error. Structuring it as an object containing objects works, but I'd like to use an array because I understand it's the only way to use a filter on ng-repeat.

I'm calling the ng-repeat like this:

<div class="list-row" ng-repeat="data in dataCollected">
  <h3 class="name"> {{data.name}} </h3>
</div>

What am I missing?


回答1:


Sorry guys, thank you for the help. The issue was that in an attempt to make my data easier to read, I had assigned names to the keys of the array using bracket notation as seen in the answer here: stackoverflow.com/questions/12244483/… ng-repeat does not like that at all. It seems the default keys are necessary.



来源:https://stackoverflow.com/questions/27682862/ng-repeat-over-array-of-objects-vs-object-containing-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!