我在将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/
答案 0 :(得分:2)
您需要在将渲染内容附加到正文之前渲染视图,因此只需交换代码即可,它应该可以正常工作。
// Render the View with the name `Tom Branton`.
myFirstView.render();
// Insert into the Document.
myFirstView.$el.appendTo("body");
答案 1 :(得分:-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());