[英]Create List input checked array for posting REST API
I've used .push() to create "List" input checked array for posting REST API. 我已经使用.push()创建用于发布REST API的“列表”输入检查数组。 But it doesn't seem right.
但这似乎不对。
When unchecking, the item in array is not removed automatically. 取消选中时,数组中的项目不会自动删除。 Anybody have a better solution, pls help me!
任何人都有更好的解决方案,请帮助我! Tks
TKS
http://plnkr.co/edit/Y0YggxvVN1epIMWAdtiU?p=preview http://plnkr.co/edit/Y0YggxvVN1epIMWAdtiU?p=preview
You could do this... it works. 您可以执行此操作。 Can't say this is the best solution though
不能说这是最好的解决方案
$scope.$watch('lists', function(lists){
$scope.count = 0;
angular.forEach(lists, function(list){
if(list.checked){
$scope.count += 1;
if (inputsList.indexOf(list.id) == -1) {
inputsList.push(list.id);
};
} else {
inputsList.pop(list.id);
}
})
}, true);
Same logic, but, modified a lil 逻辑相同,但修改了律
index.html (added ng-click) index.html(添加ng-click)
<input type="checkbox" name="list_id[]" ng-model="list.checked" value="{{list.id}}" ng-click='updateItem(list)' />
app.js (removed $scope.$watch and...) app.js(已删除$ scope。$ watch和...)
$scope.currentSelectedItem = [];
$scope.updateItem = function(item) {
if(item.checked) {
$scope.currentSelectedItem.push(item);
} else {
$scope.currentSelectedItem.pop(item);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.