angularjs 设置选中的复选框列表
angularjs set list of checkboxed checked
嗯,我有 2 个列表:
$scope.list = [{val: 1, name:'01'},{val: 2, name:'02'},{val: 3, name:'03'},{val: 4, name:'04'}]
$scope.selectedList = [{val: 2, name:'02'},{val: 4, name:'04'}]
和组合框列表 - 由列表生成:
<div ng-repeat="item in list| filter: query">
<input type="checkbox" ng-change="change(isDisabled,{{item.val}})" ng-model="isDisabled" /> {{item.name}}
</div>
那么如何将 selectedList 附加到复选框?
您需要在复选框中添加一个ng-checked。使用函数作为表达式,发送代表该复选框的项目。
ng-checked="isChecked(item)"
那么该函数只需要 return 该项目是否在 selectedList
$scope.isChecked = function(item){
return $scope.selectedList.indexOf(item) >-1;
};
嗯,我有 2 个列表:
$scope.list = [{val: 1, name:'01'},{val: 2, name:'02'},{val: 3, name:'03'},{val: 4, name:'04'}]
$scope.selectedList = [{val: 2, name:'02'},{val: 4, name:'04'}]
和组合框列表 - 由列表生成:
<div ng-repeat="item in list| filter: query">
<input type="checkbox" ng-change="change(isDisabled,{{item.val}})" ng-model="isDisabled" /> {{item.name}}
</div>
那么如何将 selectedList 附加到复选框?
您需要在复选框中添加一个ng-checked。使用函数作为表达式,发送代表该复选框的项目。
ng-checked="isChecked(item)"
那么该函数只需要 return 该项目是否在 selectedList
$scope.isChecked = function(item){
return $scope.selectedList.indexOf(item) >-1;
};