【发布时间】:2015-07-16 17:45:08
【问题描述】:
我正在使用带有chosen 指令的选择框。在我的页面中,用户可以编辑对象。引导模式中的表单打开,其中包含用户可以编辑的初始值。所有的输入形式都是必需的。
在我的其他选择框中,选项都具有与初始设置值的 id 正确匹配的 id。但是一个盒子只有三个选项,都是字符串。我不确定问题出在哪里,但选择框仅与模型中的值匹配约 5 次中的 1 次。我已经尝试过其他类似问题的解决方案,但都没有奏效。我试图在 jsfiddle 中构建一个示例,但我无法在那里复制问题。
hmtl 的一个例子:
<div class="modal-body">
<form class="form-horizontal" name="editForm" novalidate>
<div class="form-group" ng-class="{'has-error': editForm.inputType.$invalid}">
<label for="inputType" class="col-sm-2 control-label">Type:</label>
<select chosen
class="col-sm-7"
id="inputType"
name="inputType"
data-ng-model="formData.Type"
data-ng-options="type.Name as type.Name for type in typeList"
required>
<option value="">Select a type</option>
</select>
</div>
</form>
</div>
加载要编辑的数据的控制器函数:
$scope.edit = function(objectid) {
var req = {
method: 'GET',
url: $scope.url + 'node/' + objectid + '/'
}
$http(req).success(function(response) {
$scope.formData = response;
$scope.formData.id = objectid;
});
};
而typeList的结构为:
$scope.typeList = [
{"Name": "General"},
{"Name": "Super"},
{"Name": "Material"}
];
我测试了formData.Type === typeList[0].Name,当类型为General 时,它返回true。问题可能出在所选指令或引导模式上吗?
【问题讨论】:
标签: javascript angularjs twitter-bootstrap