<td ng-repeat="data in data_legend" rowspan="2"></td>
这里,data_legend 是一个动态数组,由用户从表单填充。现在的想法是将所有动态内容显示到用户和我需要知道数组中的哪个元素被编辑?
任何帮助将不胜感激:)
最佳答案
您可以将迭代中的当前数据传递给函数。
示例:
//Here I'm passing the current data object in array and its index to editData().
//$index will provide you the location of this data in array
<table ng-repeat="data in data_legend">
<tr rowspan="2" ng-click="editData(data, $index)">
<td>{{data.name}}</td>
<td>{{data.price}}</td>
<td>{{data.year}}</td>
</tr>
</table>
$scope.editData = function(data,index){
//Do something to data
}
希望这有帮助
关于javascript - 从 ng-repeat 传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37934953/