【发布时间】:2014-09-16 16:29:55
【问题描述】:
我正在尝试使用之前使用 JSON 插入的数据预填充由 angularJS 制作的表单 一切正常,除了未填充的选择选项项。
我正在使用的 JSON 示例是:
{
"date": "2014-09-14",
"enumerator": "a",
"monthreport": {
"value": "March"
},
"weekreport": {
"value": "2nd week"
},
"Maize": 23,
"Wheat": 41,
"Sorghum": 71,
"q14": "Yes"
}
monthreport 和 weekreport 是选择选项,加载表单时不会填写。 q14 是一个单选按钮,它与所有其他输入文本字段一样工作正常,包括文本和数字。 JSON是由angularJS完全生成的,当我在表单中填写数据然后保存时。
在 HTML 中以这种方式指定 select 元素:
<select ng-model="currForm.weekreport" ng-options="o.value for o in options16" name="r_weekreport" required ></select>
并且选项在控制器中设置:
...
$scope.options16= [{value:"1st week"},{value:"2nd week"},{value:"3rd week"},{value:"4th week"},{value:"5th week"}];
...
要加载 JSON,我使用 app.controller 中的常用函数:
...
$http({
method: 'GET',
url: 'http://samplesite.com/formJSON.txt'
}).success(function(data, status) {
console.log('works!!! ' + data);
$scope.currForm = data; }).error(function(data, status) {
// Some error occurred
console.log(status);
})
...
似乎一切正常……我哪里错了??
【问题讨论】:
标签: ajax json angularjs select