Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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-models 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

share|improve this question
    
Dei... Are you writing a letter, with those indentations! Check after posting. – Praveen Kumar 48 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.