【问题标题】:Backbone Collections and Handlebars eachBackbone Collections 和 Handlebars 各
【发布时间】:2012-07-10 08:58:58
【问题描述】:

我将一个名为 rowCollectionTest 的集合传递给车把模板,我认为存在语法问题。

我的车把模板上写着:

`<table id = "tableId" width= "600px" border + 1">
     {{#each row}}
     <tr>
        <td> {{ this.car }} <td>
        <td> {{ this.beans }} <td>
        <td> {{ this.exercise }} <td> 
        <td> {{ this.iron }} <td>
     </tr>`

我正在传递一个 rowCollectionTest,它是两行的集合(看看我是否可以完成这项工作)。

传递我所做的值

@$el.find("#searchContainerId").append(Handlebars.templates["resultsPage"](
    row: rowCollectionTest
)}

我的模板文件中出现错误,因此我怀疑那里存在语法错误。这是怎么回事?

【问题讨论】:

    标签: templates coffeescript each handlebars.js


    【解决方案1】:

    您必须关闭{{#each}} 并且您应该关闭您的桌子。另外,border + 1 不是有效的 HTML 属性,我想你想要border=1

    <table id = "tableId" width="600px" border="1">
      {{#each row}}
      <tr>
        <td> {{ this.car }} </td>
        <td> {{ this.beans }} </td>
        <td> {{ this.exercise }} </td> 
        <td> {{ this.iron }} </td>
      </tr>
      {{/each}}
    </table>
    

    我还修复了您的关闭 &lt;/td&gt; 标签。

    演示:http://jsfiddle.net/ambiguous/Ha6du/

    【讨论】:

    • this.car 有效吗?因为我已经在 row 的 car 属性中保存了一些东西,而 row 肯定是一些东西,并且有我保存的两个模型(我在控制台上检查过),但是控制台现在告诉我 this.car 是非法的。
    • @praks5432:rowCollectionTest 到底是什么?
    猜你喜欢
    • 2014-03-11
    • 2012-06-30
    • 1970-01-01
    • 2012-09-08
    • 2014-06-05
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多