我一直在使用模态表单,表单非常适合提交数据,但现在我需要表单来编辑数据。所以我想从服务器的回调中填充表单。表格的结构如下:
HTML:
<div class="form-group modalContent">
<label for="manufacturer">MANUFACTURER</label>
<select class="form-control" id="manufacturersList"
ng-model="form.manufacturers" required
ng-options="man.manufacturer for man in manufacturers | orderBy:'manufacturer'"></select>
</div>
AngularJS:
$scope.form = {
//The value will be the value from the callback
"manufacturers": "Acer"
}
编辑:回电
{"status":{"error":"none","code":200,"description":"none","message":"success"},"manufacturers":[{"manID":"2",
"manufacturer":"Acer"},{"manID":"3","manufacturer":"Honeywell"},{"manID":"11","manufacturer":"HP"},{"manID":"9","manufacturer":"Juniper"},{"manID":"1","manufacturer":"Lenovo"},{"manID":"6","manufacturer":"Logitech"},{"manID":"8","manufacturer":"Netgear"},{"manID":"7","manufacturer":"Other"},{"manID":"10","manufacturer":"StarTech"},{"manID":"5","manufacturer":"Viewsonic"},{"manID":"4","manufacturer":"Zebra"}]}
这不应该填充<SELECT>
中的值吗?
答案 0 :(得分:1)
ng-model
指向包含所选值的变量。
根据您在ng-options
中使用的语法,您应该manufactures
直接放置$scope
。
<select class="form-control" id="manufacturersList"
ng-model="selectedManufacturer" required
ng-options="man for man in manufacturers | orderBy:'manufacturer'">
</select>
$scope.manufacturers = ["Acer", 'HP', 'Toshiba', 'Lenovo', 'ASUS'];
中的示例
希望这有帮助