I have a template of json that I populate with data - in this case product data. For example I have the following json
// product template
$scope.productAttributes = {
"Code": null,
'Attributes':
{}
};
When a user enters some product details through a Ui and calls loadPrices() I then populate productAttributes with this function...
var loadPrices = function () {
$scope.entity = {// grabs variables from a form};
$scope.productAttributes.Code = $scope.productID.toUpperCase();
$scope.productAttributes.Attributes = $scope.entity;
$scope.productAttributes.Attributes.Term = $scope.productAttributesObj.Term;
$scope.productAttributes.Attributes.Quantity = 1;
};
and this is the result to productAttributes...
{
"Code": "CON7",
"Attributes": {
"Postcode": "n44er",
"rSize": 1000,
"Bandwidth": 10,
"Term": "36",
"Quantity": 1
}
}
So my problem is that productAttributes is overwritten every time I try to add to productAttributes when I want to add new data by calling loadPrices. I am hoping to creat 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 ideas how I can achieve this? Any advice would be appreciated.
Also, I would like to create an ID field in each "Attributes" object for example ("ID": "9e5670fa-2fd7-4858-a667-c99cb5baf0f9"). Is it posible to create guids with javascript of Angular? Many thanks