-2
<!doctype html>
<html ng-app="plunker">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js"></script>
<script src="example.js"></script>
<script src="checklist-model.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="DemoCtrl">
<label ng-repeat="role in roles">
<input type="checkbox" checklist-model="user.roles" checklist-value="role"> {{role.text}}
</label>
<button ng-click="user.roles=[];" style="margin-right: 10px">Uncheck all</button>
<button ng-click="checkNth(0)">Check first</button>
<button ng-click="checkAll()">Check all</button>
<pre>{{ user.roles | json }}</pre>
</div>
<script>
angular.module('plunker', ['checklist-model']);
var DemoCtrl = function($scope) {
$scope.roles = [{
id: 1,
text: 'guest'
}, {
id: 2,
text: 'user'
}, {
id: 3,
text: 'customer'
}, {
id: 4,
text: 'admin'
}];
$scope.user = {
roles: [$scope.roles[1]]
};
$scope.checkAll = function() {
// this first method doesn't work
//$scope.user.roles = $scope.roles;
// this one work
for (i = 0; i < $scope.roles.length; i++)
$scope.checkNth(i);
};
$scope.checkNth = function(i) {
console.log("first", JSON.stringify($scope.user.roles));
$scope.user.roles.splice(i, $scope.user.roles.length);
console.log("second", JSON.stringify($scope.user.roles));
$scope.user.roles.push($scope.roles[i])
console.log("third", JSON.stringify($scope.user.roles));
}
};
</script>
</body>
</html>
- 這裏的清單模型不像我所期望的那樣。
- 即時通訊新的角js幫助我。
- 有沒有需要添加CDN ?.
請更詳細地說明問題。 – charlietfl