Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用splice删除angularJS中的嵌套表单_Angularjs_Forms_Nested Forms_Splice - Fatal编程技术网

如何使用splice删除angularJS中的嵌套表单

如何使用splice删除angularJS中的嵌套表单,angularjs,forms,nested-forms,splice,Angularjs,Forms,Nested Forms,Splice,我有一个嵌套表单…我可以很好地添加新字段,但删除字段时遇到一些问题 我希望能够拼接对象数组中的特定位置以删除字段 目前我有 html: JSON: 将索引作为参数传递给函数 <div class="col-md-2"> <a ng-click="removeCost($index)" class="btn btn-xs btn-danger">X</a> </div> attendees.removeCost = function(inde

我有一个嵌套表单…我可以很好地添加新字段,但删除字段时遇到一些问题

我希望能够拼接对象数组中的特定位置以删除字段

目前我有

html:

JSON:


将索引作为参数传递给函数

<div class="col-md-2">
   <a ng-click="removeCost($index)" class="btn btn-xs btn-danger">X</a>
</div>
attendees.removeCost = function(index){
            var cost = attendees.formData.scenarios[0].scenarioItems[index];
            if(cost.id) {
                cost._destroy = true;
            } else {
                attendees.cost.splice(index, 1);
            }


        var cost = attendees.formData.scenarios[0].scenarioItems[index];
};
"scenarioItems": [
        {
          "cost": "",
          "costDescription": "",
        },
        {
          "cost": "",
          "costDescription": ""
        },
        {
          "cost": "",
          "costDescription": ""
        },
        {
          "cost": "",
          "costDescription": ""
        }
      ]
<div class="col-md-2">
   <a ng-click="removeCost($index)" class="btn btn-xs btn-danger">X</a>
</div>
attendees.removeCost = function(index){
            var cost = attendees.formData.scenarios[0].scenarioItems[index];
            if(cost.id) {
                cost._destroy = true;
            } else {
                attendees.cost.splice(index, 1);
            }


        var cost = attendees.formData.scenarios[0].scenarioItems[index];
};