【发布时间】:2017-10-02 02:29:14
【问题描述】:
我有一个嵌套表单....我可以在其中添加新字段,但在删除字段时遇到了一些问题。
我希望能够拼接我的对象数组中的特定位置以删除字段
目前我有...
html:
<div ng-repeat="senarioItem in attendees.formData.scenarios[0].scenarioItems" class="row">
<div ng-hide="cost._destroy">
<div class="form-group col-xs-5">
<label for="costDescription">Description</label>
<input class="form-control input-group-lg" type="text" name="costDescription" ng-model="senarioItem.costDescription"/>
</div>
<div class="form-group col-xs-2">
<label for="cost">Amount</label>
<input
class="form-control input-group-lg"
type="number"
name="cost"
ng-model="senarioItem.cost"/>
</div>
<div class="col-md-2">
<a ng-click="removeCost()" class="btn btn-xs btn-danger">X</a>
</div>
</div>
</div>
控制器:
attendees.removeCost = function(){
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];
};
JSON:
"scenarioItems": [
{
"cost": "",
"costDescription": "",
},
{
"cost": "",
"costDescription": ""
},
{
"cost": "",
"costDescription": ""
},
{
"cost": "",
"costDescription": ""
}
]
【问题讨论】:
标签: angularjs forms nested-forms splice