首页 > 代码库 > Checklist-model
Checklist-model
[checkbox写在js里]
Array of objects (pick id)
html
<label ng-repeat="role in roles"> <input type="checkbox" checklist-model="user.roles" checklist-value="http://www.mamicode.com/role.id"> {{role.text}} </label>
js
var app = angular.module("app", ["checklist-model"]); app.controller(‘Ctrl2‘, function($scope) { $scope.roles = [ {id: 1, text: ‘guest‘}, {id: 2, text: ‘user‘}, {id: 3, text: ‘customer‘}, {id: 4, text: ‘admin‘} ]; $scope.user = { roles: [2, 4] }; $scope.checkAll = function() { $scope.user.roles = $scope.roles.map(function(item) { return item.id; }); }; $scope.uncheckAll = function() { $scope.user.roles = []; }; $scope.checkFirst = function() { $scope.user.roles.splice(0, $scope.user.roles.length); $scope.user.roles.push(1); }; });
原文阅读在这儿呢^_^
[checkbox写在html里]
html
<label><input type="checkbox" checklist-model="user.roles" vhttp://www.mamicode.com/alue="a"> Administrator</label> <label><input type="checkbox" checklist-model="user.roles" value="http://www.mamicode.com/c"> Customer</label> <label><input type="checkbox" checklist-model="user.roles" value="http://www.mamicode.com/g"> Guest</label> <label><input type="checkbox" checklist-model="user.roles" valhttp://www.mamicode.com/ue="u"> User</label>
js
var app = angular.module("app", ["checklist-model"]); app.controller(‘Ctrl4a‘, function($scope) { $scope.roles = { a: ‘Administrator‘, c: ‘Customer‘, g: ‘Guest‘, u: ‘User‘ }; $scope.user = { roles: [‘c‘] }; $scope.checkAll = function() { $scope.user.roles = Object.keys($scope.roles); }; $scope.uncheckAll = function() { $scope.user.roles = []; }; $scope.checkFirst = function() { $scope.user.roles.splice(0, $scope.user.roles.length); $scope.user.roles.push(‘a‘); }; });
Checklist-model
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。