Javascript 如何在AngularJS中创建类似字典的模型绑定
在我的页面上,我从数据库中动态生成了输入标记。这些字段可能如下所示:Javascript 如何在AngularJS中创建类似字典的模型绑定,javascript,wcf,angularjs,dictionary,model-binding,Javascript,Wcf,Angularjs,Dictionary,Model Binding,在我的页面上,我从数据库中动态生成了输入标记。这些字段可能如下所示: <input id='customField-Street' type='text' /> <input id='customField-Height' type='text' /> <input id='customField-IsBlack' type="checkbox" /> <select id='customField-Car'> <option val
<input id='customField-Street' type='text' />
<input id='customField-Height' type='text' />
<input id='customField-IsBlack' type="checkbox" />
<select id='customField-Car'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
我需要键值格式,因为我的服务接受该格式的自定义数据
问题:
如何在输入字段和
$scope.customFieldsDictionary
字段之间以指定的类似字典的格式设置AngularJS双向绑定 你是从C#寄来的词典吗?如果它是来自C#的词典,它会以同样的方式工作吗?
<div ng-repeat="obj in customFieldsDictionary">
<input ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-Street' || obj.Key == 'customField-Height'" type='text'/>
<input ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-IsBlack'" type="checkbox" />
<select ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-Car'" ng-options="car for car in cars"></select>
</div>
<div ng-repeat="obj in customFieldsDictionary">
<input ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-Street' || obj.Key == 'customField-Height'" type='text'/>
<input ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-IsBlack'" type="checkbox" />
<select ng-model="obj.Value" id='{{obj.Key}}' ng-if="obj.Key ==
'customField-Car'" ng-options="car for car in cars"></select>
</div>
function ctrl($scope){
$scope.cars = ["Volvo","Saab"];
$scope.customFieldsDictionary = [{
...
}];
}