0
중첩 된 양식이 있습니다 ... 어디에 새 필드를 추가 할 수 있지만 필드를 삭제하는 데 문제가 있습니다.스플 라이스를 사용하여 angularJS에서 중첩 된 폼을 제거하는 방법
나는 ... 필드
현재내가 가지고 삭제하는 객체의 나의 배열의 특정 위치를 스플 라이스 할 수 있도록하려는
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": ""
}
]