创建列表输入检查数组,用于发布REST API

Create List input checked array for posting REST API

本文关键字:REST API 用于 列表 输入 检查 数组 创建      更新时间:2023-09-26

我使用.push()来创建"List"输入检查数组,用于发布REST API。但这似乎不对。

取消选中时,不会自动删除数组中的项。谁有更好的解决方案,请帮助我!谢谢

http://plnkr.co/edit/Y0YggxvVN1epIMWAdtiU?p =预览

你可以这样做…它的工作原理。虽然不能说这是最好的解决方案

 $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);

相同的逻辑,但是修改了一个lil

index.html(添加ng-click)

<input type="checkbox" name="list_id[]" ng-model="list.checked" value="{{list.id}}" ng-click='updateItem(list)' />

app.js(删除$scope。手表和美元…)

$scope.currentSelectedItem = [];      
$scope.updateItem = function(item) {
    if(item.checked) {
        $scope.currentSelectedItem.push(item);
    } else {
        $scope.currentSelectedItem.pop(item);
    }   
}