标签:2-2 func 使用 mod col obj blog lis 记录
angular应用中,ng-repeat很方便的实现了数组的展示:
<div ng-controller=‘myCtrl‘> <ul> <li ng-repeat="obj in list"> {{obj.name}} <ul> <li ng-repeat="child in obj.children" ng-click="childClick($index, child, $parent.$index)"> {{child.name}} </li> </ul> </li> </ul> </div> <script> angular.module("myApp",[]) .controller("myCtrl",function($scope){ $scope.list = [ {name: ‘1‘, children: [{name:‘1-1‘}]}, {name: ‘2‘, children: [{name:‘2-2‘}]} ] $scope.childClick = function (index, obj, parentIndex) { console.log(index,obj,parentIndex); } }) </script>
这里我们用到了ng-repeat嵌套来实现二维数组,而定位显然使用二维数组下标是最好不过的,里层的ng-repeat使用 $index 记录下标位置没错,那么如果将外层的 $index 也传入记录呢? $parent.$index 可以实现!
标签:2-2 func 使用 mod col obj blog lis 记录
原文地址:http://www.cnblogs.com/guofan/p/7692564.html