大佬教程收集整理的这篇文章主要介绍了JavaScript – 使用ng-repeat和过滤器的Array中的Object的$index,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个数组的对象,我正在从firebase拉下来.我正在对象使用Ng重复,然后相应地显示数据.我试图将索引作为一个routeparam传递给“编辑”控制器.在这种情况下,我想按照预期的方式提取对象数据.但是,当我过滤ng-repeat时,我得到过滤内容的索引.找到真正的索引我在哪里错了?
.config(['$routeProvider','$LOCATIOnProvider',function($routeProvider,$LOCATIOnProvider) { $routeProvider .when('/profiles/:index',{ templateUrl: '../views/profile.html',controller: 'profileCtrl' });
路线在上面,控制器在下面
.controller('profileCtrl',function( $scope,$routeParams ){ $scope.teamProfile = $scope.ourTeam[$routeParams.index]; $scope.index = $routeParams.index; });
最后再来一遍html的片段.
<div class="profilename"><a href="/profiles/{{$index}}">{{member.namE}}</a><span class="handle">{{member.handlE}}</span></div>
$index
只是重复元素的迭代器偏移量(0..length-1)
如果您想要原始索引,则必须在过滤之前将其添加到您的集合中,或者完全不过滤元素.
一种可能的方法:
angular.forEach(members,function(member,indeX){ //Just add the index to your item member.index = index; }); <div ng-repeat="member in members"> <a href="/profiles/{{member.index}}"> </div>
现在,这种信息似乎比其他任何东西更像ID.希望这已经是记录的一部分,你可以绑定到而不是使用索引.
以上是大佬教程为你收集整理的JavaScript – 使用ng-repeat和过滤器的Array中的Object的$index全部内容,希望文章能够帮你解决JavaScript – 使用ng-repeat和过滤器的Array中的Object的$index所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。