0

我正在为应用程序使用主干、车把、jquery。以下代码行不起作用

this.$el.find('.quiz-container').append(quiz.tmplt.result(this.collection.toJSON()));

模板是

<h2 class="score">Congratulation ABCD! You 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>

这是我的 JSON 文件

[{
    "qid": "1001",
    "qtext": "This is 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 is 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 is question three?",
    "options": [{"id":"opt1", "str":"5%"},{"id":"opt2", "str": "2.5%"},{"id":"opt3", "str": "11%"},{"id":"opt4", "str": "0%"}],
    "answer": ["opt3"]}
]

我知道,我可以拆分这个模板并使用 collection.each 方法,我可以从 JSON 文件中渲染每个对象,但我想保留它的第一个模板并直接从集合数据中渲染。

提前致谢

维克拉姆

4

0 回答 0