0

所以我正在尝试为我的一个模板实现一些把手指令,但我有点迷失如何将 JSON 传递给模板以便它可以在指令中使用它。

目前我在我的视图中有这个:

application = require 'application'
template = require('views/templates/appLayout')

module.exports = class AppLayout extends Backbone.Marionette.Layout
    template: template, loggedin: true
    el: "body"

    regions:
        content: "#content"

这在视图的模板中:

<div class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <a class="brand" href="#"><i class="icon-leaf"> </i> Application</a>

      <div class="nav-collapse"><!-- Other nav bar content -->

        <!-- The drop down menu -->
        <ul class="nav pull-right">
            {{#if loggedin}}
              <h1>Welcome back!</h1>
            {{else}}
                <input id="login" type="email" placeholder="E-mail" class="flat">
              <input id="password_login" type="password" placeholder="Password" class="flat">
              <button class="btn btn-primary btn-mini login btn-embossed">Sign in</button>
              <button class="btn btn-danger btn-mini register btn-embossed ">Sign up</button>
            {{/if}}
        </ul>
      </div>

    </div>
  </div>
</div>

<div id="content" class="container"></div>

现在模板的 else 块正在被渲染,但我希望 if 块被渲染。有谁知道如何正确实现这一点?

4

1 回答 1

4

您需要定义布局serializeData以发送所需的 JSON。你可以在这里看到一个例子:https ://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/common/views.js

文档:https ://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md#viewserializeddata

于 2013-06-01T22:36:31.950 回答