javascript - traverse dynamic number of options in json array -
i building mcq application has multiple questions varying number of options. so, question 1 can have 4 options , question 2 can have 2 options , on.
i have generated json array backend gives me data tells me number of options each question has.
but stuck on part of displaying options on browser.
my json object looks this:
[ { "option1": "asdasd", "option2": "ajda", "option3": "hsadb", "option4": "asd", "question": "hello", "quest_id": 32 }, { "option1": "dsf", "option2": "afs", "question": "asdad", "quest_id": 34 } ]
i want display dynamically each question corresponding options , radio buttons besides them.
also have array tells me number of options in each [4,2] says question 1 has 4 options , question 2 has 2 options. tried apply ng-repeat using angular js in array gives "dupes error" duplicate elements not allowed. appreciated. in advance.
{test:[{question: "hello", answers:['asda','asdasd','asdasd'], "quest_id": 32}]}
use structure , ng-repeat should this.
<div ng-repeat="question in test"> {{question.question}} <div ng-repeat="obj in question.answers"> <input type="radio" ng-model="testresult[question.quest_id].answer" value="obj"> </div>
something should work
Comments
Post a Comment