Requirement: need to push an JSON array inside an array of JSON objects.Final Structure Needed like Below,
var memberArray = [{
"Identifier": "1",
"Question": [{
"QuestionId": "1",
"QuestionDetails": "Alcohol",
"Answer": "1"
}, {
"QuestionId": "2",
"QuestionDetails": "Smoking",
"Answer": "2"
}]
}, {
"Identifier": "2",
"Question": [{
"QuestionId": "1",
"QuestionDetails": "Alcohol",
"Answer": "3"
}, {
"QuestionId": "2",
"QuestionDetails": "Smoking",
"Answer": "4"
}]
}];
//I am having each member in memberArray as a single JSON object
var member = {
"Identifier": "",
"Question": [{
"QuestionId": "",
"QuestionDetails": "",
"Answer": ""
}, {
"QuestionId": "",
"QuestionDetails": "",
"Answer": ""
}]
};
each json values i am displaying using ng-model in the screen. I am getting the member details as the first tab output (i.e) memberArray will contain Question array as empty like below
memberArray = [{
"Identifier": "1",
"Question": []
}, {
"Identifier": "2",
"Question": []
}];
//in the next tab i am getting the question details separately for each member
//and pushing with respect to each member like below
var Ques = [{
"QuestionId": "",
"QuestionDetails": "",
"Answer": ""
}, {
"QuestionId": "",
"QuestionDetails": "",
"Answer": ""
}];
for (var i in memberArray) {
if (i.Identifier == uuid) {
memberArray[i].Questions = angular.copy(Ques);
}
}
uuid is the one i am passing for this function, now i am having the memberArray
as expected. But ng-model
s i am having as similar to memberArray
structure(e.g)
ng-model = memberArray[index1].Questions[index2].answer
where index1 and index2 will be set dynamically to print all the Question details in the screen.
ISSUE
Since I am displaying the memberArray fully as a table structure. Once i am changing the first member's Question it reflecting in the second member's Questions also. Please help me with this