角JS内的NG-重复序列结合示波器数据形成 [英] Angular JS binding scope data within ng-repeat to form
本文介绍了角JS内的NG-重复序列结合示波器数据形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字段身份证在$ scope.data项目,名与功放的集合; 年龄,被显示在用NG-重复指令的观点。
对于每一组的项目,有一个相应的编辑按钮。
I have a collection of items in $scope.data with fields "id","name" & "age", that are being displayed in the view using ng-repeat directive. For each set of items, there is a corresponding "edit button".
我希望能够访问值的特定集合为其编辑按钮是pressed项目。
I want to be able to access values for the particular set of items for which edit button was pressed.
HTML:
<div ng-controller="Ctrl">
<div ng-repeat="i in data">
Name: {{i.name}}
Age: {{i.age}}
<form ng-submit="submit()">
<input type="text" ng-model="i.id"/>
<input type="submit" value="Edit" />
</form>
</div>
</div>
脚本:
function Ctrl($scope)
{
$scope.data = [
{id:1,name:"Alex",age:22},
{id:2,name:"Sam", age:28}
];
$scope.submit = function() {
//access id of user for which edit was clicked
};
}
什么是做到这一点的正确方法?
What is the right way to do this?
推荐答案
试试这个:
HTML
<form ng-submit="submit(i.id)">
JavaScript的:
JavaScript:
$scope.addBrandModelFilter = function(useId) {
// you have userId
};
这篇关于角JS内的NG-重复序列结合示波器数据形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文