我已关注此帖:How do I bind to list of checkbox values with AngularJS?
从复选框列表中检索数据并将其作为Json传递。
我的代码是:
<span ng-repeat="b in neighborhood">
<input id="{{b.Id}}" class="checkcheck" type="checkbox" ng-model="b.checked" ng-change="selection.indexOf(b) > -1"
ng-click="toggleSelection(b)">
{{ b.Name }}
这是我的控制器代码:
$scope.toggleSelection = function toggleSelection(b) {
var idx = $scope.selection.indexOf(b);
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
else {
$scope.selection.push(b);
}
console.log($scope.selection);
ProgramsWS.GetByNeighborhood({ neighborhoodList: $scope.selection }, function (resp) {
console.log(resp);
})
};
问题是,在最后的json中,我得到的是这样的东西:
0 b { Name="Name1", Id=51, checked=true, more...}
1 b { Name="Name2", Id=43, checked=true, more...}
问题是: Web服务无法识别在此过程中添加的“已检查”。我该如何删除它?
答案 0 :(得分:1)
您可以使用delete
关键字从对象中删除属性。例如,给定以下对象:
var b = { Name:"Name1", Id:51, checked:true };
删除checked
属性:
delete b.checked;
这导致以下对象:
{ Name:"Name1", Id:51 }