我有一个包含 10 个复选框的表单。默认情况下,angular js 在单个复选框上触发。我只想在提交操作时获取所有选中的复选框值。这是我的代码...
<form name="thisform" novalidate data-ng-submit="booking()">
<div ng-repeat="item in items" class="standard" flex="50">
<label>
<input type="checkbox" ng-model="typeValues[item._id]" value="{{item._id}}"/>
{{ item.Service_Categories}}
</label>
</div>
<input type="submit" name="submit" value="submit"/>
</form>
$scope.check= function() {
//console.log("a");
$http.get('XYZ.com').success(function(data, status,response) {
$scope.items=data;
});
$scope.booking=function(){
$scope.typeValues = [];
console.log($scope.typeValues);
}
我得到的是空数组。
有人能告诉我如何仅在提交事件时获取所有选中的复选框值。
最佳答案
<div ng-repeat="item in items">
<input type="checkbox" ng-model="item.SELECTED" ng-true-value="Y" ng-false-value="N"/>
</div>
<input type="submit" name="submit" value="submit" ng-click="check(items)"/>
$scope.check= function(data) {
var arr = [];
for(var i in data){
if(data[i].SELECTED=='Y'){
arr.push(data[i].id);
}
}
console.log(arr);
// Do more stuffs here
}
关于javascript - 如何在angularjs中的提交功能上获取ng-repeat复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31000636/