<body>
例如,我想把这模拟数据数组对象利用急用ng-repeat循环页面显示,我想在点击的时候把当时对象的点击选中的count+1.我该怎么获得这个当时元素呀
如果是这样呢!我想获取support,对support进行操作+1,gid是作品的id,但是每个id只能+1,类似点赞功能!
回复内容:
<body>
例如,我想把这模拟数据数组对象利用急用ng-repeat循环页面显示,我想在点击的时候把当时对象的点击选中的count+1.我该怎么获得这个当时元素呀
如果是这样呢!我想获取support,对support进行操作+1,gid是作品的id,但是每个id只能+1,类似点赞功能!
本文#来源gaodai.ma#com搞##代!^码7网
搞代gaodaima码
$index
可以获取元素在数组的下标, 然后根据下标获取元素
<code><div>{{ item.count }}</div></code>
ng-repeat里的元素li添加ng-click方法,通过 $event.target 来获取当前元素
<code><ul> <li> {{item.name}} <button>{{itemNumber}}</button> </li></ul><script> $scope.itemNumber=0; $scope.addItem=function($index){ angular.forEach($scope.items,function(item,index){ if($index==index){ $scope.itemNumber++; } }) }</script></code>
个人的实现方法大概是这样