如何将angularjs对象绑定到其键和值 [英] how to bind angularjs objects to their keys and values
本文介绍了如何将angularjs对象绑定到其键和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通读了一些有关角度模型绑定的文章,出于好奇,我想知道是否也可以将键绑定到输入,
I read through some articles on angular model binding, and just out of curiousity, I was wondering if its possible to bind keys to input too,
http://jsfiddle.net/x3azn/jM28y/4/
所以我希望ot通过输入框更新主 arr
并实现2种方式的键绑定。
so I am hoping ot update the main arr
through the input boxes and achieve 2 way key-binding.
这可能吗?
推荐答案
如此处所述使用ngRepeat =>将输入绑定到基元数组。不可编辑的输入,是的,您可以,但是不能那样做
as explained here Binding inputs to an array of primitives using ngRepeat => uneditable inputs, yes you can, but not that way
尝试一下
function ctrl($scope) {
$scope.arr = [{name:'1', lastname: '2'},
{name:'3', lastname: '4'},
{name:'5', lastname: '6'}]
}
<div ng-repeat="person in arr">
<input type="text" ng-model="person.name" />
<input type="text" ng-model="person.lastname" />
</div>
这篇关于如何将angularjs对象绑定到其键和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文