ng-repeat 将索引值传递给函数 [英] ng-repeat passing index value to a function
本文介绍了ng-repeat 将索引值传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将添加了 ng-repeat 的特定元素的 $index 值传递给 javascript 函数.我的代码示例:
I need to pass a $index value of a specific element, added with ng-repeat, to a javascript function. My code sample:
<tr ng-repeat="cells in CouponsList.CellPhones">
<td><button ng-click="doStuff($index+1)">{{cells.localVendorAddress}}</button></td>
现在我添加了几个按钮,当按下特定按钮时,我需要将它的特定 $index 发送到 doStuff($index) 函数.有什么想法吗?
Now I am adding several buttons and when a specific button is pressed I need to send it's specific $index to the doStuff($index) function. Any idea?
推荐答案
请看这里:http://jsbin.com/yeweh/4/edit
<a href="" ng-repeat="s in students" ng-click="doit($index)">{{s.name}} - {{s.class}} </a>
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope){
$scope.doit= function(index){
alert(index)
}
$scope.students = [
{name: 'Aa_Student', class: 'A_Class'},
{name: 'Ab_Student', class: 'A_Class'},
{name: 'Ac_Student', class: 'B_Class'},
{name: 'Ba_Student', class: 'B_Class'},
{name: 'Bb_Student', class: 'C_Class'},
{name: 'Bc_Student', class: 'C_Class'}];
});
这篇关于ng-repeat 将索引值传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文