我正在尝试传递当前所选项目的索引,以便我可以使用它的索引来深入挖掘某些嵌套数组。这是我到目前为止所拥有的。
我的控制员:
$scope.scope1Change = function() {
$scope.array3.length = 0;
$scope.array4.length = 0;
$scope.array2 = $scope.array[$scope.scope1].areas;
angular.forEach($scope.array[$scope.scope1].areas, function(index) {
angular.forEach(index.sections , function(indx){
$scope.array3.push(indx);
});
});
angular.forEach($scope.array[$scope.scope1].areas, function(tex) {
angular.forEach(tex.sections , function(texi){
angular.forEach(texi.lessons , function(texa){
$scope.array4.push(texa);
});
});
});
};
html:
<select class="selectLevel1" ng-model="scope2" ng-change='scope2Change()'
ng-options='area.name for area in array2 track by area.id' >
</select>
<select class="selectLevel2" ng-model="scope3" ng-change='scope3Change()'
ng-options='obj.name for obj in array3 track by obj.id' >
</select>
所以我想要当前所选项目的索引,以便它知道要查看哪个数组然后填充它下面的选择列表(以及下面的几个,我只是想让它在以下工作第一)。如果我在括号中硬编码像$ scope.array [0]这样的值,它可以正常工作,但我试图让它动态地工作。 [$ scope.scope1]返回完整的对象,当我只是查看其索引作为数字值时。有角度的任何方式来实现这一点?谢谢!
答案 0 :(得分:0)
知道了!
$ scope.array [$ scope.array.indexOf($ scope.scope1)]