Reputation: 2509
Update: I'm trying to construct a table out of my data structure(ie section1) and then allow users to add rows to the table to insert more rows and save them to my datastructure.
I have an array newArr in the form of key value pairs. When somebody clicks a button, I want to be able to push the newArray into the Groups.I dont seem to be able to push into the Groups array. Chrome dev tools shows Groups as Objects and i'm not certain how to loop through and append to each item of the Groups Object. Feel free to modify the $scope.section1 to a different datastructure that could make it easier to push new items to it.
$scope.section1 = [{
"id":1, "Name": "Section 1: Inventory",
"Groups":[
{"cell" : "Number", "cellValue" : "value1"},
{"cell" : "Location", "cellValue" : "value2"},
{"cell" : "Severity", "cellValue" : "value3"}
],
"FootNotes":[
{"templateurl" : "components/section/templates/notes/section1.notes.html"}
]
}]
var newArr = {"cellValue" : "value4","cellValue" : "value5","cellValue" : "value6"}
So the output should look like
$scope.section1 = [{
"id":1, "Name": "Section 1: Inventory",
"Groups":[
{"cell" : "Number", "cellValue" : "value1", "cellValue" : "value4"},
{"cell" : "Location", "cellValue" : "value2", "cellValue" : "value5"},
{"cell" : "Severity", "cellValue" : "value3", "cellValue" : "value6"}
],
"FootNotes":[
{"templateurl" : "components/section/templates/notes/section1.notes.html"}
]
}]
Upvotes: 0
Views: 78
Reputation: 7202
$scope.section1[0].Groups.push({
"cell" : "Number",
"cellValue" : "value1",
"anotherCellValue" : "value4"
});
Upvotes: 0
Reputation: 4531
You can't have two properties with the same name. You have cellValue two times for Object group. What are you trying to do?
You'd better like to change the structure itself:
...
"Groups": [
{
name: "group1",
values: ['value 1', 'value 2', 'value 3']
}
]
Then, adding one more value to group1:
$scope.section1[0].Groups.values.push('value 4')
Note than I'm trying to respect the whole structure that you already have, but I don't meaning this is the optimal way to solve your problem
Upvotes: 1