NG-不断重复的对象数组与包含对象的对象 [英] ng-repeat over array of objects vs. object containing objects

查看:75
本文介绍了NG-不断重复的对象数组与包含对象的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在几乎所有我见过的NG-重复的例子中,数据的结构如下所示:

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'}];

不过,我可以得到NG-重复工作的唯一方法是,如果我构建这样的数据:

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'}};

构建它作为一个数组导致NG重复做绝对没有。它甚至没有给出一个错误。构建它作为包含对象的对象的作品,但我想,因为我知道这是用在NG-重复过滤器的唯一方法使用数组。

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.

我打电话NG重复这样的:

I'm calling the ng-repeat like this:

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

我在想什么?

推荐答案

对不起伙计们,感谢大家的帮助。问题是,在试图让我的数据更容易阅读,因为在这里的回答看出我已经分配的名称使用括号表示法阵的钥匙:的 stackoverflow.com/questions/12244483/ ... NG重复不喜欢,在所有。似乎缺省键是必要的。

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.

这篇关于NG-不断重复的对象数组与包含对象的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆