我有一个运行Ionic框架并尝试验证至少选中了一个复选框,但不确定如何操作。 “required”属性似乎仅适用于要检查的所有复选框。
<label class="item item-input">routines</label>
<ion-checkbox name="routine" ng-repeat="item in routines"
ng-model="item.checked"
ng-checked="item.checked"
ng-required="true">
{{ item.name }}
</ion-checkbox>
我很感激您的反馈
由于
答案 0 :(得分:1)
控制器:
int *(&arry)[10] = ptrs;
Html
.controller('AppCtrl', function($scope) {
$scope.Routines = [
{name:'Routines1', selected:false},
{name:'Routines2', selected:false},
{name:'Routines3', selected:false},
{name:'Routines4', selected:false},
{name:'Routines5', selected:false},
{name:'Routines6', selected:false},
{name:'Routines7', selected:false}
];
$scope.selectedRoutines = [];
$scope.updateRoutines = function(item){
console.log("array : " + JSON.stringify(item.selected));
if(item.selected && ($scope.selectedRoutines.indexOf(item.name) < 0)){
$scope.selectedRoutines.push(item.name);
console.log("added : " + $scope.selectedRoutines);
}else{
$scope.selectedRoutines.splice($scope.selectedRoutines.indexOf(item.name), 1);
console.log("remove : " + $scope.selectedRoutines);
}
};
});
验证:你可以查看<div class="item-accordion"
ng-repeat="item in Routines track by $index">
<ion-item class="item item-checkbox">
<label class="checkbox">
<input type="checkbox" ng-model="item.selected" ng-change="updateRoutines(item)">
</label>
{{item.name}}
</ion-item>
</div>
希望这在某种程度上有所帮助..!