码迷,mamicode.com
首页 > 其他好文 > 详细

ng-repeat嵌套的$index

时间:2017-10-19 15:53:52      阅读:230      评论:0      收藏:0      [点我收藏+]

标签: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 可以实现!

ng-repeat嵌套的$index

标签:2-2   func   使用   mod   col   obj   blog   lis   记录   

原文地址:http://www.cnblogs.com/guofan/p/7692564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!