如果你只是想顯示勾選或者你可以只應用一個過濾器,但你需要從undefined
過濾值切換至true
如果你不想被卡住不能再顯示所有。
HTML:
<button ng-click="filterChecked()">Filter checked: {{ checked }}</button>
<div class="recipient" ng-repeat="person in people | filter:checked">
<input type='checkbox' ng-model="person.isChecked" />
<img ng-src="{{person.img}}" />{{ person.name }}
<div class="email">{{ person.email }}</div>
</div>
控制器:
// Apply a filter that shows either checked or all
$scope.filterChecked = function() {
// if set to true or false it will show checked or not checked
// you would need a reset filter button or something to get all again
$scope.checked = ($scope.checked) ? undefined : true;
}
如果你想獲得已檢查了所有和提交的表單數據你可以簡單地通過數組循環:
控制器:
// Get a list of who is checked or not
$scope.getChecked = function() {
var peopleChkd = [];
for (var i = 0, l = $scope.people.length; i < l; i++) {
if ($scope.people[i].isChecked) {
peopleChkd.push(angular.copy($scope.people[i]));
// Remove the 'isChecked' so we don't have any DB conflicts
delete peopleChkd[i].isChecked;
}
}
// Do whatever with those checked
// while leaving the initial array alone
console.log('peopleChkd', peopleChkd);
};
Check out my fiddle here
注意person.isChecked
在HTML僅加入。
請在這裏填寫更多的單詞'我可以得到選擇的項目列表' – swapnesh 2014-09-24 18:21:04