【问题标题】:Double wrapped ItemView content with backbone.js and marionette.js使用backbone.js 和marionette.js 双重包装的ItemView 内容
【发布时间】:2013-01-09 21:42:51
【问题描述】:

这是一个名为 activatetwoitem 的 ItemView 模板

<!--  <tr>-->
<td><%= gatewayJson.serial %></td>
<td>In Inventory</td>
<td><%= gatewayJson.macaddress %></td>
<!-- </tr>-->

这里是名为 activatetwo 的 CompositeView 模板

<table class="table table-hover">
<thead>
    <tr>
        <th>Gateway ID</th>
        <th>In Group</th>
        <th>MAC Address</th>
    </tr>

</thead>

<tbody></tbody></table>

这里是 ItemView

Step2View = Backbone.Marionette.ItemView.extend
    template: activatetwoitem
    tagName: 'tr'

这是复合视图

Step2Views = Backbone.Marionette.CompositeView.extend
    itemView: Step2View
    template: activatetwo
    itemViewContainer: "tbody"

现在我得到了这个......

<table class="table table-hover">
<thead>
    <tr>
        <th>Gateway ID</th>
        <th>In Group</th>
        <th>MAC Address</th>
    </tr>
</thead>
<tbody>
    <tr>
        <!--  <tr>-->
        <tr>
            <td>AX1OD</td>
            <td>In Inventory</td>
            <td>secret mac address</td>
            <!-- </tr>-->
        </tr>
    </tr>
    <tr>
        <!--  <tr>-->
        <tr>
            <td>12RUM</td>
            <td>In Inventory</td>
            <td>secret mac address</td>
            <!-- </tr>-->
        </tr>
    </tr>
</tbody>

我为什么会这样?如果我取出 tagName 那么不知何故仍然出现(当然是一个 div 而不是第二个 tr)有什么想法吗?

【问题讨论】:

  • 这很奇怪...我经常使用相同的设置。你能发布一个重现问题的 JSFiddle 吗?
  • 你也做注释掉的html吗?把它拿出来固定我的。
  • 嗯,不。不能说我以前做过……但老实说,当我看到你的帖子时,我从来没有想过这是一个潜在的问题。我得试试看会发生什么。
  • 你使用下划线还是lodash作为模板?我在旧的 lodash 版本中遇到了 cmets 问题...
  • 使用 underscore.js 模板。我也在使用这个 require.js 插件github.com/ZeeAgency/requirejs-tpl ...虽然我不认为这应该没关系。

标签: backbone.js marionette


【解决方案1】:

我没有看为什么,但是当我从模板中取出注释的 html 时,多余的包装器就消失了。太糟糕了,因为我喜欢模板中的注释行来提醒我应该去那里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多