2014-08-27 66 views
0

我想通过当前选定项目的索引,以便我可以使用它的索引来深入挖掘某些嵌套数组。这是迄今为止我所拥有的。当前选定项目的角度传递索引(在选择列表中)

我的控制器:

$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

Got it! $ scope.array [$ scope.scope1]]

相关问题