由网友(陌影阡尘)分享简介:我渲染键:值对象数组,像这样NG-重复: < DIV NG控制器=mainCtrl> < DIV NG重复=记录中记录> < DIV NG重复=(键,值)记录> <输入NG模型=键/>:<输入NG模型=值/> <...
我渲染键:值对象数组,像这样NG-重复:
< DIV NG控制器=mainCtrl> < DIV NG重复=记录中记录> < DIV NG重复=(键,值)记录> <输入NG模型=键/>:<输入NG模型=值/> < / DIV> < / DIV>< / DIV>
JS:
VAR mainCtrl =功能($范围){$ scope.records = [ {'键1':'VAL1}, {'KEY2':'val2的'} ];}
问题是,键和值无法通过输入标签进行更新。出于某种原因,它成为制造NG重复迭代(键,值)后一种方式的结合。
小提琴: http://jsfiddle.net/BSbqU/1/
我怎样才能使一个双向绑定?或者我应该以不同的方式解决这个问题,那么嵌套的NG-重复?
解决方案 < DIV NG控制器=mainCtrl>< DIV NG重复=记录中记录> <输入NG模型=record.name/>:<输入NG模型=record.value/> < / DIV>< / DIV>
和JS的:
VAR对myApp = angular.module('对myApp',[]);VAR mainCtrl =功能($范围){$ scope.records = [{'名':'键1','值':'VAL1},{'名':'键2','值':'val2的'} ];}
I am rendering key:value object array with ng-repeat like this:
<div ng-controller="mainCtrl">
<div ng-repeat="record in records">
<div ng-repeat="(key, value) in record">
<input ng-model="key" />: <input ng-model="value" />
</div>
</div>
</div>
JS:
var mainCtrl = function($scope){
$scope.records = [
{'key1':'val1'},
{'key2':'val2'}
];
}
Problem is that keys and values cannot be updated through input tags. For some reason it becomes one way binding after making ng-repeat iterate over (key,value).
Fiddle: http://jsfiddle.net/BSbqU/1/
How can I make it a two way binding? Or should I approach this problem in a different way then nested ng-repeat?
解决方案<div ng-controller="mainCtrl">
<div ng-repeat="record in records">
<input ng-model="record.name" />: <input ng-model="record.value" />
</div>
</div>
And the JS:
var myApp = angular.module('myApp', []);
var mainCtrl = function($scope){
$scope.records = [
{'name':'key1','value':'val1'},
{'name':'key2', 'value':'val2'}
];
}
相关推荐
最新文章