我遇到了AngularJS材料的網站,並與一些教程玩耍。關於複選框最後一個例子弄得我有點(this tutorial site)AngularJS複選框
<div flex="100" flex-gt-sm="50" layout="column">
<div >
<fieldset class="standard">
<legend>Using <input type="checkbox"></legend>
<div layout="row" layout-wrap flex>
<div ng-repeat="item in items" class="standard" flex="50">
<label>
<input type="checkbox" ng-checked="exists(item, selected)"
ng-click="toggle(item, selected)"/>
{{ item }}
</label>
</div>
</div>
</fieldset>
</div>
</div>
我想知道是否有可能來命名HTML複選框不同,如(A,B,C,..),但數量仍然工作( 1,2,3,...)在控制器?
angular.module('checkboxDemo2', ['ngMaterial']).controller('AppCtrl', function($scope) {
$scope.items = [1,2,3,4,5];
$scope.selected = [];
$scope.toggle = function (item, list) {
var idx = list.indexOf(item);
if (idx > -1) {
list.splice(idx, 1);
}
else {
list.push(item);
}
};
$scope.exists = function (item, list) {
return list.indexOf(item) > -1;
};
});
這個工作對我來說: 我只是想補充一點,我改變了語法的東西:$ scope.items = [{名稱: 'A',值:1} ,{名稱: 'B',值:2},{名稱: 'C',值:3},{名稱: 'd',值:4}]; – WirJun