显然,上面是在AngularJs语法无效的,然而,无论是item in array
也不(key, value) in item
会自己做的伎俩。有没有办法将两者结合成一个单一的声明(如上所述)或其他方式来做到这一点?ng-repeat =“(key,value)in arr中的项目”?
我有键/值对的地图看起来像这样:
$this.colorsHash = {
'05/04/2015': { sum: 540, color: 'rgb(176,145,219)' },
'05/10/2015': { sum: 379, color: 'rgb(161,111,107)' },
'05/13/2015': { sum: 429, color: 'rgb(173,138,118)' },
'05/19/2015': { sum: 478, color: 'rgb(209,108,161)' },
'05/15/2015': { sum: 596, color: 'rgb(200,200,196)' },
'05/18/2015': { sum: 337, color: 'rgb(102,114,121)' }
}
我使用此图以生成一个传说,但是,这个传说可能有20+的价值观,所以我想突破它被分成相同大小的块并且并排显示它们。我已经想出了这部分。它创建n个阵列的具有相同长度的阵列,像这样:
$this.splitArr = [
[
{ '05/04/2015': { sum: 540, color: 'rgb(176,145,219)' } },
{ '05/10/2015': { sum: 379, color: 'rgb(161,111,107)' } },
{ '05/13/2015': { sum: 429, color: 'rgb(173,138,118)' } }
],
[
{ '05/19/2015': { sum: 478, color: 'rgb(209,108,161)' } },
{ '05/15/2015': { sum: 596, color: 'rgb(200,200,196)' } },
{ '05/18/2015': { sum: 337, color: 'rgb(102,114,121)' } }
]
]
我的问题是如何使用纳克重复在每个键/值对的时候它嵌套阵列内。这里是我使用的代码,它让我获得每个对象,但是我不知道如何访问该对象的键/值。
<ul style="list-style: none;" ng-repeat="item in Main.splitArr">
<li ng-repeat="obj in item">
<div style="height: 20px; width: 20px;
background-color: {{/*I need the object's value.color here*/}};
display: inline-block;"></div> =
<span ng-bind="/*I need the object's key here*/"></span>
</li>
</ul>
Downvoters关心,为什么“这个问题不发表评论显示任何研究工作;它不清楚或没有用“? – mhodges