AngularJS判断checkbox/复选框是否选中并实时显示

来源:互联网 发布:网络投资app 编辑:程序博客网 时间:2024/05/17 01:32

最近因为项目原因重新捡起来了AngularJS ,遇到老问题复选框选中和值的问题。
先贴以前网上找的解决方案
http://www.cnblogs.com/CheeseZH/p/4517701.html
个人感觉太麻烦了,代码太多,然后自己找了点资料,现在如下自己的解决方案
全选checkbox按钮

<input type="checkbox" ng-model="all"> <span>全选</span>

ng-repeat里面的checkbox按钮
<form name="testFrom"  action="">     <div  ng-repeat="x in shoppingCartList" ><input type="checkbox" ng-checked="all" value="{{x.userId}}" name="userId" "></div>        </div></form name="testFrom">
获取值的方法 
$scope.deleteUserProduct = function(){$scope.userIdList= '';                           //先赋值 '' 避免append的时候 undefinedvar formEle = document.testFrom.elements.userId; //获取form表单name等于userId元素for (var i = 0; i < formEle.length; i++) {       //遍历userId元素if(foemEle[i].checked){  //判断是否选中$scope.userIdList +=formEle[i].value+",";}}}
java后台代码
String [] shopId=request.getUserIdList().split(",");
短短的几行Js代码解决了.如果你有更好的解决方案,可以底下留言。一起探讨。哈哈