我有一个嵌套数组,如下所示: ***编辑阵列*
nested = {
"_id": 24,
"itemId": 15,
"testGroups": [
{
"TestGroupName": null,
"testGroup": [
{
"TestName": "ddasdasd",
"TestType": 1,
"testGroup": []
},
{
"TestName": "dsadasddasd",
"TestType": 2,
"testGroup": []
},
{
"TestName": "adsdasd",
"TestType": 0,
"testGroup": [
{
"TestGroupName": "dasdasd",
"testGroup": [
{
"TestName": "dasdasd",
"TestType": 1,
"testGroup": []
}
]
},
{
"TestGroupName": "dasdasd",
"testGroup": [
{
"TestName": "dasdasd",
"TestType": 2,
"testGroup": []
}
]
}
]
},
{
"TestName": "dasdasddasd",
"TestType": 2,
"testGroup": []
}
]
}
]
}
我需要为TestName
我尝试使用$parent.$index
和$index
的组合,但它不适用于子项目,因为它将0显示为索引。
答案 0 :(得分:0)
使用ng-init
<div ng-repeat="item in arr" ng-init="parentIndex = $index" >
<div ng-repeat="subitem in item.subitems" ng-init="chilIndex = $index">
{{parentIndex}}.{{chilIndex}}
</div>
</div>
演示
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.arr = [
{
item:"",
subitems:[
{
item:"",
subitems:[
{
item:"",
subitems:[
{
item:"",
subitems:[
]
},
{
item:"",
subitems:[
]
}
]
}
]
},
{
item:"",
subitems:[
]
}
]
},
{
item:"",
subitems:[
{
item:"",
subitems:[
]
},
{
item:"",
subitems:[
]
}
]
}
]
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="item in arr" ng-init="parentIndex = $index" >
<div ng-repeat="subitem in item.subitems" ng-init="chilIndex = $index">
{{parentIndex}}.{{chilIndex}}
</div>
</div>
</div>