如何使用splice删除angularJS中的嵌套表单
我有一个嵌套表单…我可以很好地添加新字段,但删除字段时遇到一些问题 我希望能够拼接对象数组中的特定位置以删除字段 目前我有 html: JSON:如何使用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
将索引作为参数传递给函数
<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];
};