选择AngularJS中的所有指令
我正在对我的应用程序使用指令。我有一个问题,如果-选择AngularJS中的所有指令,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我正在对我的应用程序使用指令。我有一个问题,如果- 我单击“全选”按钮,虽然它写入了数组,但没有写入 选中复选框。同样的问题,取消选中All,尽管它会清空 但它不会取消选中复选框 如果我选中2或3个随机复选框并单击全选按钮,则不会选中所有复选框 虽然它将值写入pushArray。但问题是勾选和取消勾选复选框 $scope.items = [{id:1, name:"abc"},{id:2, name:"def"},{id:3, name:"ghi"}]; $scope.pushArray =
- 我单击“全选”按钮,虽然它写入了数组,但没有写入 选中复选框。同样的问题,取消选中All,尽管它会清空 但它不会取消选中复选框
- 如果我选中2或3个随机复选框并单击全选按钮,则不会选中所有复选框
$scope.items = [{id:1, name:"abc"},{id:2, name:"def"},{id:3, name:"ghi"}];
$scope.pushArray = [];
<table>
<tr ng-repeat="e in items">
<td class="text-right">
{{e.id}}
<input type="checkbox" checklist-change="imChanged()" checklist-model="pushArray" checklist-value="e.id" >
</td>
</tr>
</table>
$scope.items=[{id:1,名称:“abc”},{id:2,名称:“def”},{id:3,名称:“ghi”}];
$scope.pushArray=[];
{{e.id}}
我认为你推的对象列表是错误的。您只需映射列表并将id
传递到$scope
编辑:将$scope.pushArray
用作对象而不是数组时,效果良好
HTML
<body ng-controller="selection">
<table>
<tr ng-repeat="e in items">
<td>
<input type="checkbox" checklist-model="pushArray.ids" checklist-value="e.id"> {{e.name}}
</td>
</tr>
</table>
{{pushArray.ids | json}}
<br />
<button ng-click="select_all();">Select All</button>
<button ng-click="unselect_all();">Unselect All</button>
</body>
希望它对你有用 我更新了
清单模型上的示例
,并解决了这个问题。查看它们虽然它对我有效,但我不清楚。如果我将“$scope.pushArray”作为数组,那有什么问题。您还可以使用“$scope.pushArray”将数组添加到此对象。
var app = angular.module('app', ["checklist-model"]);
app.controller('selection', ['$scope', function($scope) {
$scope.items = [{
id: 1,
name: "abc"
}, {
id: 2,
name: "def"
}, {
id: 3,
name: "ghi"
}];
$scope.pushArray = { ids: []}; // Works fine when using it as an object
//$scope.pushArray = [];
$scope.select_all = function() {
$scope.pushArray.ids = $scope.items.map(function(item) { return item.id; });
};
$scope.unselect_all = function() {
$scope.pushArray.ids = [];
};
}]);