我如何跟踪指数累计在2嵌套NG-重复 [英] How do I keep track of the cumulative index in 2 nested ng-repeats
问题描述
在一个指令的观点,我有两个NG-重复。
该指令建立了一个表格,每一个表格单元格的数据是从另一个数据源。
此数据源需要两个中继器的累计指标。
selectedKandidaat.AntwoordenLijst [$指数] .value的
我只已经拿到了当前$索引或$父。$指数。因此,要保持跟踪,我想在Antwoordenlijst使用整体指数的[ $指数]我需要跟踪指数的变量。我可以只使用创建和更新视图索引变量。
事情是这样的:
..
{{totalIndex = 0}}
< TR NG重复=opgave在opgaven>
< TD NG重复=,在opgave.Items项目>
{{totalIndex + = 1}}
..
实际code
<表类=表>
< TR NG重复=opgave在opgaven>
< TD NG重复=,在opgave.Items项目>
<选择NG模型=selectedKandidaat.AntwoordenLijst [$指数] .value的
NG-选项=alternatief在item.Alternatieven alternatief>
< /选择>
< / TD>
< / TR>
< /表>
每个纳克重复创建它自己的范围,所以找到你需要在父范围内计数的总数。
< DIV NG重复=一个在items1>
父:{{$指数}}
< DIV NG重复=b在items2itemcell>
孩子:{{$指数}}
总:{{TOTALCOUNT}}
< / DIV>
< / DIV>
总:{{TOTALCOUNT}}
和在新的计 itemcell
derective
app.directives
.directive('itemcell',函数(){
返回{
限制:'A',
链接:功能($范围,iElement,iAttrs){
如果(!$范围。$父。$ parent.totalCount){
。$范围$父$ parent.totalCount = 0。
}
。$ $范围母公司$ parent.totalCount ++。
}
}
})
您也可以尝试通过$父。$指数来算当前索引,但它只能如果你有相同的项目集合计数。
In the view of a directive I have two ng-repeats. This directive builds a table, and the data of every table cell is from another datasource. This datasource needs the cumulative index of the two repeaters.
selectedKandidaat.AntwoordenLijst[$index].Value
I only have got the current $index, or the $parent.$index. So to keep track of the overall index that I want to use in Antwoordenlijst[$index] I will need to keep track of an index variable. Can I just use create and update an index variable in the view.
Something like this:
..
{{ totalIndex = 0 }}
<tr ng-repeat="opgave in opgaven">
<td ng-repeat="item in opgave.Items">
{{ totalIndex += 1 }}
..
The actual code
<table class="table">
<tr ng-repeat="opgave in opgaven">
<td ng-repeat="item in opgave.Items">
<select ng-model="selectedKandidaat.AntwoordenLijst[$index].Value"
ng-options="alternatief for alternatief in item.Alternatieven">
</select>
</td>
</tr>
</table>
Each ng-repeat creates it's own scope, so to find the total count you need count in the parent scope.
<div ng-repeat="a in items1">
parent: {{$index}}
<div ng-repeat="b in items2" itemcell>
child: {{$index}}
total: {{totalCount}}
</div>
</div>
total: {{totalCount}}
and counter in new itemcell
derective
app.directives
.directive('itemcell', function () {
return {
restrict: 'A',
link: function ($scope, iElement, iAttrs) {
if (!$scope.$parent.$parent.totalCount) {
$scope.$parent.$parent.totalCount = 0;
}
$scope.$parent.$parent.totalCount++;
}
}
})
You also can try to count current index via $parent.$index, but it works only if you have collections with the same items count.
这篇关于我如何跟踪指数累计在2嵌套NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!