【发布时间】:2013-09-13 16:20:47
【问题描述】:
这里我基本上设置了 3 个选择列表
<label for="organization">Organization</label>
<select ng-change="setOrganization()" ng-model="form.organization"
ng-options="o.name as o.displayName for o in organizations" required></select>
<label for="board">Board</label>
<select ng-change="setBoard()" ng-model="form.board"
ng-options="b.id as b.name for b in boards" required></select>
<label for="board">List</label>
<select ng-change="setList()" ng-model="form.list"
ng-options="l.id as l.name for l in lists" required></select>
JS:
$scope.setOrganization = function(){
$scope.lists = {};
mySerivce.get('....', function(boards){
$scope.boards = angular.fromJson(boards);
$scope.$apply();
});
};
$scope.setBoard = function(){
mySerivce.get('...', function(lists){
$scope.lists = angular.fromJson(lists);
$scope.$apply();
});
};
因此,当一个组织被选中时,我会得到板子并用板子数据填充第二个选择字段。再次选择电路板时,将获取分配给电路板的所有列表,并使用此数据设置第三种选择字段。在所有选择字段都具有选定值之前,表单将保持无效。
当用户更改组织时,所有字段都会被清除。但是 form.$valid 对象仍然是 true。哪里有问题?当没有选择任何值时,表单必须是无效的,因为这些字段是必需的。有什么想法吗?
【问题讨论】:
-
您可以在 get 回调中设置 $scope.form.board = null 吗?
-
@ZackArgyle 效果很好!让这成为一个答案
标签: javascript angularjs angularjs-scope