I am working with a json template that I fill with product data. Here is an example of the json structure:
// product template
$scope.productAttributes = {
"Code": null,
'Attributes':
{}
};
When a user inputs product details through a UI and triggers the loadPrices() function, I update the productAttributes like this...
var loadPrices = function () {
$scope.entity = {// retrieve form variables};
$scope.productAttributes.Code = $scope.productID.toUpperCase();
$scope.productAttributes.Attributes = $scope.entity;
$scope.productAttributes.Attributes.Term = $scope.productAttributesObj.Term;
$scope.productAttributes.Attributes.Quantity = 1;
};
This is the resulting productAttributes object...
{
"Code": "CON7",
"Attributes": {
"Postcode": "n44er",
"rSize": 1000,
"Bandwidth": 10,
"Term": "36",
"Quantity": 1
}
}
My issue is that every time I call loadPrices, the productAttributes gets overwritten instead of adding new data. I want to achieve a structure like this...
{
"Code": "CON7",
"Attributes": {
"Postcode": "n44er",
"Size": 1000,
"Bandwidth": 10,
"Term": "36",
"Quantity": 1
},
"Code": "CON34",
"Attributes": {
"Postcode": "nww45",
"Size": 10,
"Bandwidth": 10,
"Term": "36",
"Quantity": 1
},
"Code": "CON89",
"Attributes": {
"Postcode": "sw23ed",
"Size": 101,
"Bandwidth": 101
}
}
Any suggestions on how I can accomplish this? Any advice would be greatly appreciated.
Additionally, I would like to include an ID field in each "Attributes" object (e.g., "ID": "9e5670fa-2fd7-4858-a667-c99cb5baf0f9"). Is it possible to generate GUIDs using JavaScript or Angular? Thank you!