国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Angularjs+bootstrap+table多選(全選)支持單擊行選中實現編輯、刪除功能

2019-11-19 17:01:02
字體:
來源:轉載
供稿:網友

最終實現效果:

最終效果

index.html

<!DOCTYPE html><html> <head>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>  <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.3.1.js"></script>  <link  rel="external nofollow" rel="stylesheet">  <link rel="stylesheet" href="style.css" rel="external nofollow" >  <script src="script.js"></script> </head> <body ng-app="routerApp">  <div ng-controller="zdTable">  <table class="table table-bordered" >    <thead>     <tr>        <th>          <input type="checkbox" ng-model="selectAll" ng-change="changeAll()" /> 選擇</th>        <th>序號</th>        <th>用戶</th>        <th>備注</th>        <th>操作</th>      </tr>    </thead>    <tbody>      <tr ng-repeat="row in datas" ng-init="outerIndex = $index" ng-click="changeCurrents(row, $event)">        <td><input type="checkbox" ng-model="row.checked" ng-click="changeCurrent(row, $event)" /></td>        <td ng-bind="outerIndex+1"></td>        <td ng-repeat="tddata in row | filterTable">            {{tddata}}        </td>        <td>           <button type="button" class="btn btn-info" ng-click="zdTableEdit(row, $event)">編輯</button>           <button type="button" class="btn btn-danger" ng-click="zdTableRemove(row, $event)">刪除</button>        </td>      </tr>    </tbody>  </table> <div>已選數量:{{count}}</div> <div>已選對象:{{selectData}}</div></div> </body></html>

script.js

// Code goes herevar routerApp = angular.module('routerApp', [ 'ngAnimate', 'ngSanitize',                    'ui.bootstrap']);routerApp.controller('zdTable', [    '$scope',    function(scope) {      console.log('controller');     //初始化數據      scope.datas = [        {name:'admin1', rem:'備注'},         { name:'admin2', rem:'備注'},         { name:'admin3', rem:'備注'}        ];      scope.count = 0;//已選擇數量       scope.selectData = [];//已選對象      //選擇單個(取消選擇單個      scope.changeCurrent = function(current, $event) {       //計算已選數量 true加, false減        scope.count += current.checked ? 1 : -1;        //判斷是否全選,選數量等于數據長度為true    scope.selectAll = scope.count === scope.datas.length;        //統計已選對象        scope.selectData = [];        angular.forEach(scope.datas, function(item) {          if(item.checked){            scope.selectData[scope.selectData.length] = item;          }        });       $event.stopPropagation();//阻止冒泡      };      //單擊行選中      scope.changeCurrents = function(current, $event) {        if(current.checked == undefined){          current.checked = true;        }else{          current.checked = !current.checked;        }        scope.changeCurrent(current, $event);      };    //全選(取消全選      scope.changeAll = function() {        //console.log(scope.selectAll);        angular.forEach(scope.datas, function(item) {          item.checked = scope.selectAll;        });        scope.count = scope.selectAll ? scope.datas.length : 0;        if (scope.selectAll) {          scope.selectData = scope.datas;        } else {          scope.selectData = [];        }      };      //編輯事件      scope.zdTableEdit = function(item, $event){        console.log(item);        $event.stopPropagation();//阻止冒泡      };      //刪除事件      scope.zdTableRemove = function(item, $event){        console.log(item);        $event.stopPropagation();//阻止冒泡      };    } ]);//去掉不需要顯示的字段  routerApp.filter('filterTable', function() {  return function(obj) {    var newObj = {};    for ( var i in obj) {      var property = obj[i];      if(i != 'checked'){        newObj[i] = property;      }    }    //console.log(newObj);    return newObj;  };});

以上所述是小編給大家介紹的Angularjs bootstrap table多選(全選)支持單擊行選中實現編輯、刪除功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙阴县| 酒泉市| 巴青县| 灵山县| 绥宁县| 仁化县| 屏南县| 中宁县| 长泰县| 兴国县| 广平县| 庐江县| 渑池县| 山阳县| 扎囊县| 中山市| 犍为县| 贺兰县| 越西县| 郑州市| 建平县| 宜君县| 儋州市| 龙江县| 渭南市| 敦煌市| 皋兰县| 肃南| 桐乡市| 旺苍县| 高陵县| 西吉县| 镇远县| 招远市| 枣庄市| 天柱县| 襄垣县| 沙洋县| 合作市| 浑源县| 响水县|