angularjs實(shí)現(xiàn)多選框分段全選效果實(shí)現(xiàn)
angularjs 實(shí)現(xiàn)多選框分段全選效果
在前臺開發(fā)過程中,列表批量選擇是一個開發(fā)人員經(jīng)常遇到的功能,列表批量選擇的實(shí)現(xiàn)方式很多,但是原理基本相同,本文主要來講AngularJs如何簡單的實(shí)現(xiàn)列表批量選擇功能。
效果如下

html代碼
<div class="form-group1" style="margin-top: 15px;">
<div class="input-group">
<div class="input-group-addon no-border" style="padding-left: 0px;float: left;">
<p>角色權(quán)限:</p>
</div>
</div>
</div>
<div class="" ng-repeat="todotype in todolist" style="margin-bottom: 30px;">
<div class="" style="display: flex;">
<div class="" style="background-color: rgb(229,172,78);width: 10%;padding: 1px 5px;line-height: 25px;height: 28px;">
<input style="margin-bottom: 8px;" type="checkbox" ng-model="$parent.selectAll[$index]" ng-click="changeAll($index)" />
<span style="color: white;font-weight: 600;">
{{todotype.type}}
</span>
</div>
<div class="" style="padding-left: 24px;width: 100%;">
<div class="row">
<div class="col-md-2 col-sm-2" ng-repeat="obj in todolist[$index].permissionList" style="margin-bottom: 10px;">
<input type="checkbox" ng-click="funcChange($parent.$index)" ng-model="obj.isSelected" />
<span style="line-height: 25px;">{{obj.name}}</span>
</div>
</div>
</div>
</div>
</div>html里面簡單建立一個表格,與批量選擇相關(guān)的只有兩處。
一處是ng-click="changeAll($index),用來做全選的操作;
ng-click="funcChange($parent.$index)"用來判斷當(dāng)前大類里內(nèi)容是否被全選。
判斷是否全選是用ng-model進(jìn)行判斷 第一處ng-model="$parent.selectAll[$index]"是判斷這一大類是否全選;
ng-model="obj.isSelected"是判斷每一大類的每一項(xiàng)的選擇;
控制器里的代碼js文件
// 獲取數(shù)據(jù) 這里具體post請求就不寫了
$scope.todolist = res.data.data;
for(var i = 0; i < $scope.todolist.length; i++) {
angular.forEach($scope.todolist[i].permissionList, function(i) {
i.isSelected = false;
})
}
// 數(shù)據(jù)類型如下
$scope.list = [{
permissionList: [{
name: 'Golde',
// birthday: '2000-01-10',
isSelected: false
},
{
name: 'King',
// birthday: '1990-01-10',
isSelected: false
},
{
name: 'Mark',
// birthday: '19890-01-10',
isSelected: false
},
{
name: 'Marie',
// birthday: '2010-01-10',
isSelected: false
}
],
type: "制造資源管理"
}, {
permissionList: [{
name: 'Golde1',
// birthday: '2000-01-10',
isSelected: false
},
{
name: 'King1',
// birthday: '1990-01-10',
isSelected: false
},
{
name: 'Mark1',
// birthday: '19890-01-10',
isSelected: false
},
{
name: 'Marie1',
// birthday: '2010-01-10',
isSelected: false
}
],
type: "制造資源管理2"
}, {
permissionList: [{
name: 'Golde2',
// birthday: '2000-01-10',
isSelected: false
},
{
name: 'King2',
// birthday: '1990-01-10',
isSelected: false
},
{
name: 'Mark2',
// birthday: '19890-01-10',
isSelected: false
},
{
name: 'Marie2',
// birthday: '2010-01-10',
isSelected: false
}
],
type: "制造資源管理3"
}];
// 具體方法如下所示
// 這里初始化數(shù)組 上來全為空
$scope.selectAll = [];
// 對于對象進(jìn)行操作的時候(點(diǎn)擊),會執(zhí)行funcChange
// 判斷對象數(shù)組中isSelected 是否為 true或false,在決定select是否為true
$scope.changeAll = function(index) { //全選/取消全選
angular.forEach($scope.todolist[index].permissionList, function(v, k) {
v.isSelected = $scope.selectAll[index];
})
};
$scope.funcChange = function(index) { // 當(dāng)所有都選中時
$scope.selectAll[index] = true;
angular.forEach($scope.todolist[index].permissionList, function(v, k) {
$scope.selectAll[index] = $scope.selectAll[index] && v.isSelected;
});
};具體邏輯已經(jīng)寫得很清楚
以上就是angularjs實(shí)現(xiàn)多選框分段全選效果實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于angularjs多選框分段全選的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
解決angularjs WdatePicker ng-model的問題
今天小編就為大家分享一篇解決angularjs WdatePicker ng-model的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
Angular2中select用法之設(shè)置默認(rèn)值與事件詳解
在Angular.JS中可以使用數(shù)組或?qū)ο髣?chuàng)建一個下拉列表選項(xiàng)。關(guān)于Angular.js中select的基礎(chǔ)相信大家應(yīng)該都已經(jīng)了解了,那么下面這篇文章主要給大家介紹了Angular2中select用法之設(shè)置默認(rèn)值與事件的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-05-05
angularjs封裝bootstrap時間插件datetimepicker
這篇文章主要介紹了angularjs封裝bootstrap時間插件datetimepicker 的相關(guān)資料,需要的朋友可以參考下2016-06-06
AngularJS實(shí)現(xiàn)標(biāo)簽頁的兩種方式
這篇文章分別給大家介紹了AngularJS實(shí)現(xiàn)標(biāo)簽頁的兩種方式,一種是通過普通指令實(shí)現(xiàn)標(biāo)簽頁,另外一種是通過自定義指令實(shí)現(xiàn)的標(biāo)簽頁,有需要的朋友們可以來參考借鑒,下面來一起看看吧。2016-09-09
Angular指令封裝jQuery日期時間插件datetimepicker實(shí)現(xiàn)雙向綁定示例
這篇文章主要介紹了Angular指令封裝jQuery日期時間插件datetimepicker實(shí)現(xiàn)雙向綁定示例,具有一定的參考價值,有興趣的可以了解一下。2017-01-01
Angular中ng?update命令force參數(shù)含義詳解
這篇文章主要為大家介紹了Angular中ng?update命令force參數(shù)含義詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
基于angular2 的 http服務(wù)封裝的實(shí)例代碼
這篇文章主要介紹了基于angular2 的 http服務(wù)封裝實(shí)例代碼,2017-06-06
Angular中封裝fancyBox(圖片預(yù)覽)遇到問題小結(jié)
這篇文章主要介紹了Angular中封裝fancyBox(圖片預(yù)覽)遇到的問題小結(jié),需要的朋友可以參考下2017-09-09

