2

If I have the following 2 arrays bound to a compiled Handlebars template:

questions: [
    {id:1, text:'question1', answers: [
        {id: 1, text:'answer1'},
        {id: 2, text:'answer2'}
    ]},
    {id:2, text:'question2', answers: [
        {id: 1, text:'answer3'},
        {id: 2, text:'answer4'}
    ]}
],
userAnswers: [
    {questionId:1, answerId:2}
]

I would rather not change the data structure and need to do the following (pseudo-code):

for each (question in questions) 
    render question text
    render user answer text

(note that there may be a question without an answer)

If I use 'each' in my Handlebars template:

{{#each question}}

Is there a way to get the answer id from the userAnswers object?

Then map this back to questions to get the text?

e.g. is there some kind of selector syntax such as:

{{../userAnswers[questionId=id].answerId}}
4

0 回答 0