0

我在使用 BLM 将模型传递给视图时遇到了困难。我决定按照他的概述步骤了解更多信息。我发现他创建的“Baseview”是 Backbone.Layout 并创建了一个小提琴,我认为它遵循了这个过程但无法让它工作......

    var MyFirstView = Backbone.Layout.extend({

    template: '<li><a href="#test" title="" class="recordName"><%= first_name %> <%= surname %></a><a href="#" class="button edit">Edit</a><a href="#" class="button delete">Delete</a></li>',


});

// Create a new instance.
var myFirstView = new MyFirstView({
    model: {
        first_name: 'Tom',
        surname: 'Branton'
    }
});

// Insert into the Document.
myFirstView.$el.appendTo("body");

// Render the View with the name `Tom Branton`.
myFirstView.render();

任何人都可以帮忙吗?小提琴是http://jsfiddle.net/jmsherry/WHY67/1/

4

2 回答 2

2

您需要在将渲染内容附加到正文之前渲染视图,因此只需交换代码即可。

// Render the View with the name `Tom Branton`.
myFirstView.render();

// Insert into the Document.
myFirstView.$el.appendTo("body");
于 2014-02-05T08:02:58.690 回答
-1

使用木偶。 https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.layout.md

<script id="layout-template" type="text/template">
  <section>
    <navigation id="menu">...</navigation>
    <article id="content">...</article>
  </section>
</script>

AppLayout = Backbone.Marionette.Layout.extend({
  template: "#layout-template",

  regions: {
    menu: "#menu",
    content: "#content"
  }
});

var layout = new AppLayout();
layout.render();

layout.menu.show(new MenuView());

layout.content.show(new MainContentView());
于 2014-02-03T13:37:39.410 回答