项目常用功能模块(2)-ngRepeat 动态生成表单下的全选/单选

来源:互联网 发布:嫌疑人影评知乎 编辑:程序博客网 时间:2024/06/06 10:07

测试后HTML,

<table class="table table-condensed" id="QueryTab" style="background:#E0FFFF;"><thead><tr><th width="10px"><input type="checkbox"ng-click="checkAll()" ng-model="box.totalState"/></th><th>主题</th><th>条件</th></tr></thead><tbody><tr ng-repeat="data in filterSel track by $index"><td><input type="checkbox" ng-click="checkOne()" ng-init="$parent.box.state[$index]=false" ng-model="$parent.box.state[$index]"/></td><td>{{data.theme}}</td><td>{{data.condition[0].key}}</td></tr></tbody></table>


好,js,

/** *全选、单选 */$scope.box={};$scope.checkAll=function(){for(var key in $scope.box.state){$scope.box.state[key]=$scope.box.totalState;}}$scope.checkOne=function(){console.log($scope.box);for(var key in $scope.box.state){if($scope.box.state[key]==false){$scope.box.totalState=false;return;}}$scope.box.totalState=true;}


结束

原创粉丝点击