Within my json object named "flowComponents," there is a string called "name" and an array of strings labeled "edition." As an example:
{
"_id": "553e87f3205465e83b46999b",
"name": "FLOWCOMPONENT_CONTACTCOMBINATION_EDITION",
"__v": 0,
"edition": [
"billing",
"billingDelivery",
"default",
"deliveryAddressOnly",
"deliveryBillingLicensee",
"deliveryBillingLicenseeWithWrapper",
"deliveryLicensee",
"deliveryOnlyCopyToAll",
"licenseeDelivery",
"sassDefault",
"sassDeliveryOnlyCopyToAll"
]
}
In order to incorporate/append another edition to this existing flowComponents object, I have designed a form featuring a dropdown with the names of the current flowComponents and a text area that generates an array from each line of text:
<form ng-submit="addToExistingFlowComponent()">
<div class="interact">
<select ng-model="existingName" chosen options="flowComponents" ng-options="item as item.name for item in flowComponents" data-placeholder="Select a flow component...">
</select>
</div>
<div class="interact">
<label class="interact-label">Enter each edition on a new line.</label>
<textarea id="text_area" placeholder="Edition" ng-model="existingEditionList" ng-list=" " ng-trim="false"></textarea>
</div>
<button type="submit">Submit</button>
</form>
This function in my controller is responsible for adding editions:
$scope.addToExistingFlowComponent = function(){
if(!$scope.existingName || $scope.existingName === '') { return; }
var existingFC = $scope.existingName._id;
sendAppData.postEdition( existingFC, {
edition: $scope.existingEditionList
});
$scope.existingName = '';
$scope.existingEditionList = '';
};
Furthermore, here is the method used to post data to the server:
this.postEdition = function(existingFC, newEdition) {
return $http.post('/new-flow-component', newEdition).success(function(data){
flowComponents.push(data);
});
};
An issue arises where the data is being pushed to a new object rather than being added to the existing one. Though I can pass the _id of the existing object into the existingFC parameter, I am struggling to access it within the function(data) in order to include it in the appropriate edition array.