Checklist-model

2005 ワード

【checkboxはjsに書いてあります.】
Aray of object(pick id) 
html
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



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');
  };
});
転載先:https://www.cnblogs.com/miny-simp/p/7136202.html