Angular Js 里面table, checkbox制作可多选,单选的表格
来源:互联网 发布:淘宝9.9的鼠标垫 编辑:程序博客网 时间:2024/05/16 08:45
Angular Js 里面table, checkbox制作可多选,单选的表格
查看别人的方法再加拓展,忘记了原博客地址;
主要实现主表格里面可以展开子表,子表的信息可以多选也可以单选,并绑定数据,算是三级选中吧?;
复选框只有两个值:true或者false,因此在AngularJS中,一般都是将复选框的ng-model绑定为一个布尔值属性,通过这两个布尔值来决定其勾选状态,以及通过其勾选状态来设置被绑定的属性值为true或false。我们来看以下示例:
图片预览:
html:
<div> <input type="checkbox" ng-model="select_allList" ng-change="selectAll()"> 全部选中<br><br> <table class="table table-hover table-responsive workSheet-form"> <thead> <tr> <th>选择</th> <th>大单位</th> <th>小单位</th> </tr> </thead> <tbody ng-repeat="item in customerList"> <tr> <td> <label for="flag">全选此单位 <input id="flag" type="checkbox" ng-model="item.select_all" ng-change="selectItem(item)"> </label> 展开子表 <input type="checkbox" ng-model="myVar"> </td> <td>{{item.deliverAdress}}</td> <td>{{item.workUunitName}}</td> </tr> <tr ng-show="myVar"> <td colspan="3"> <table> <thead> <tr> <th>选择</th> <th>姓名</th> <th>品名</th> <th>数量</th> </tr> </thead> <tbody> <tr ng-repeat="x in item.listBoxProduct"> <td> <input type="checkbox" ng-model="x.checked" ng-change="selectOne(x,item)"> </td> <td>{{x.name}}</td> <td>{{x.infoName}}</td> <td>{{x.quantity}}</td> </tr> </tbody> </table></td> </tr> </tbody> </table> </div>
js代码:
$scope.m = []; $scope.checked = []; $scope.selectAll = function () { if($scope.select_allList) { $scope.checked = []; angular.forEach($scope.customerList, function (item) { console.log("true:"+item.select_all ); item.select_all = true; angular.forEach(item.listBoxProduct, function (i) { i.checked = true; $scope.checked.push(i); }) }) }else { angular.forEach($scope.customerList, function (item) { item.select_all = false; $scope.checked = []; angular.forEach(item.listBoxProduct, function (i) { i.checked = false; }) }) } console.log("$scope.checked"+JSON.stringify($scope.checked)); }; $scope.selectItem = function (item) { console.log("$scope.select_all"+item.select_all); if(item.select_all) { // $scope.checked = []; angular.forEach(item.listBoxProduct, function (i) { console.log("true:"+item.select_all ); i.checked = true; $scope.checked.push(i); }) }else { angular.forEach(item.listBoxProduct, function (i) { console.log("false:"+item.select_all ); i.checked = false; // $scope.checked = []; var index = $scope.checked.indexOf(i); $scope.checked.splice(index, 1); }) } console.log("$scope.checked"+JSON.stringify($scope.checked)); }; $scope.selectOne = function (x,item) { var index = $scope.checked.indexOf(x); console.log("index"+index); if(x.checked && index === -1) { $scope.checked.push(x); } else if (!x.checked && index !== -1){ $scope.checked.splice(index, 1); }; //后续添加当子表全选时主表相应记录的checkBox 选中 console.log(JSON.stringify($scope.checked)); };
选中的数据:
阅读全文
0 0
- Angular Js 里面table, checkbox制作可多选,单选的表格
- table 里面的 checkbox 全选,取消,单选,选中一行后选中行高亮
- table表格的制作
- js控制checkbox单选
- js 获得某个DIV里面的checkbox
- 10010---Angular JS 表格
- 制作动态的表格js
- Latex 制作表格table
- <table>标签,制作表格
- 关于table里面的checkbox选择无效的问题
- Jquery删除table里面checkbox选中的多个行
- Jquery如何删除table里面checkbox选中的多个行
- table表格的checkbox的全选和选中
- 利用js实现checkbox的单选功能
- angular js 点击单选按钮加传值
- table表格里面td的点击冒泡事件
- js的table表格添加与修改
- Android里ListView里面添加CheckBox实现单选。
- Linux和unix中 awk 的print浅谈
- 05-方法values演示) 06-Map集合-常见子类对象) 07-Map集合-HashMap存储自定义对象) 08-Map集合-TreeMap存储自定义对象) 1 2
- C++学习笔记--类型转换函数
- 《大宇:Qt从入门到精通》目录
- ES6 fetch函数与后台交互
- Angular Js 里面table, checkbox制作可多选,单选的表格
- linux 系统安装 RabbitMQ
- rsa key的使用
- SSM初次学习后的项目笔记
- 使用Chrome修改user agent模拟微信内置浏览器
- 用Prim和Kruskal算法实现图的最小生成树
- 转载育碧七年
- python3.6.1安装pyinstalll ,python打包exe
- 育碧拐点