我正在尝试将全局值或某种缓存保留在ngRepeat
. 解释起来有点复杂,所以这就是我想做的。
我使用了docs:ngRepeat中的示例代码。
<body>
<div ng-init="friends = [
{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'},
{name:'Johanna', age:28, gender:'girl'},
{name:'Joy', age:15, gender:'girl'},
{name:'Mary', age:28, gender:'girl'},
{name:'Peter', age:95, gender:'boy'},
{name:'Sebastian', age:50, gender:'boy'},
{name:'Erika', age:27, gender:'girl'},
{name:'Patrick', age:40, gender:'boy'},
{name:'Samantha', age:60, gender:'girl'}
]">
<ul>
<li ng-repeat="friend in friends>
{{friend.name}} who is {{friend.age}} years old.
</li>
</ul>
</div>
我想总结age
每次重复的价值。结果应如下所示:
- 25岁的约翰。25 -解释:25+0
- 30岁的杰西。55-解释:25+30
- 28岁的约翰娜。83 -解释:55+28
- 15岁的乔伊。98 -解释:83+15
- ...
可以在此处找到用于实验的 Plunkr http://plnkr.co/edit/VFiTOnmQ4cyqgNMDa9L4。
谢谢!