backbone.js - Backbone view in not rendering from collection.toJSON() -
i using backbone, handlebars, jquery app. following code line not working
this.$el.find('.quiz-container').append(quiz.tmplt.result(this.collection.tojson()));
template is
<h2 class="score">congratulation abcd! have scored {{score}} !!!</h2> <table> <thead> <tr> <th>question</th> <th>your answer</th> <th>correct answer</th> </tr> </thead> <tbody> {{#each qtext}} <tr> <td>{{this}}</td> <td> {{#each ../answer}} <span>{{this}}</span> {{/each}} </td> </tr> {{/each}} </tbody> </table>
here json file
[{ "qid": "1001", "qtext": "this question one?", "options": [{"id":"opt1", "str":"15%"},{"id":"opt2", "str": "16%"},{"id":"opt3", "str": "17%"},{"id":"opt4", "str": "19%"}], "answer": ["opt2"]}, { "qid": "1002", "qtext": "this question two?", "options": [{"id":"opt1", "str":"item0"},{"id":"opt2", "str": "item1"},{"id":"opt3", "str": "item2"},{"id":"opt4", "str": "item3"}], "answer": ["opt1"]}, { "qid": "1003", "qtext": "this question three?", "options": [{"id":"opt1", "str":"5%"},{"id":"opt2", "str": "2.5%"},{"id":"opt3", "str": "11%"},{"id":"opt4", "str": "0%"}], "answer": ["opt3"]} ]
i know, can split template , using collection.each method can render each object json file, want keep 1st template , render directly collection data.
thanks in advance
vikram
Comments
Post a Comment