Select AngularJS 中的所有指令
Select All directive in AngularJS
我在我的应用程序中使用 Checklist model 指令。我有问题,如果 -
- 我点击了 select all 按钮虽然它写入了数组但是它没有
select 复选框。 Uncheck All 虽然它清空了同样的问题
模型,但它不会取消选中复选框。
- 如果我 select 2 或 3 个随机复选框并单击 Select 所有按钮它不会 select 所有复选框。
尽管将值写入 pushArray。但问题是选中和取消选中复选框。
$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>
我认为您推送的是错误的完整对象列表。您只需要映射列表并将 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>
JS
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 = [];
};
}]);
希望对你有用!
我更新了 checklist-model
上的示例并解决了这个问题。查看它们 http://vitalets.github.io/checklist-model/
我在我的应用程序中使用 Checklist model 指令。我有问题,如果 -
- 我点击了 select all 按钮虽然它写入了数组但是它没有 select 复选框。 Uncheck All 虽然它清空了同样的问题 模型,但它不会取消选中复选框。
- 如果我 select 2 或 3 个随机复选框并单击 Select 所有按钮它不会 select 所有复选框。
尽管将值写入 pushArray。但问题是选中和取消选中复选框。
$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>
我认为您推送的是错误的完整对象列表。您只需要映射列表并将 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>
JS
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 = [];
};
}]);
希望对你有用!
我更新了 checklist-model
上的示例并解决了这个问题。查看它们 http://vitalets.github.io/checklist-model/