MarionetteJS:应用程序区域与布局
MarionetteJS: Application Regions vs. Layouts
我正在阅读最新版本 (2.3.0) 的文档,它说应用程序区域现在已被弃用。
Application Regions
Warning: deprecated This feature is deprecated. Instead of using the
Application as the root of your view tree, you should use a Layout
View. To scope your Layout View to the entire document, you could set
its el to 'body'. This might look something like the following: var
RootView = Marionette.LayoutView.extend({ el: 'body' });
在大多数教程中,包括 David Sulc 的书 Backbone Marionette:A Gentle Introduction,它使用以下代码片段向应用程序添加区域。
下面的示例使用 addRegions,我应该怎么做?
即
var ContactManager = new Marionette.Application({});
ContactManager.addRegions({
mainRegion: "#main-region"
});
var ContactView = Marionette.ItemView.extend({
template: "#whatever",
ui: {
button: ".button".
},
events: {
"click @ui.button": "click",
},
click: function () {
console.log("do stuff here...");
}
});
ContactManager.on("start", function () {
var contactView = new ContactView({
model: someModel
});
ContactManager.mainRegion.show(contactView);
});
改用布局视图。
例如您可以这样做:
var ContactManager = new Marionette.Application({});
var LayoutView = Backbone.Marionette.LayoutView.extend({
template: "#layout-view-template",
regions: {
menu: "#menu",
content: "#content"
}
});
ContactManager.layout_view = new LayoutView();
ContactManager.layout_view.render();
我从来没有直接将区域添加到我的应用程序对象。
我正在阅读最新版本 (2.3.0) 的文档,它说应用程序区域现在已被弃用。
Application Regions
Warning: deprecated This feature is deprecated. Instead of using the Application as the root of your view tree, you should use a Layout View. To scope your Layout View to the entire document, you could set its el to 'body'. This might look something like the following: var RootView = Marionette.LayoutView.extend({ el: 'body' });
在大多数教程中,包括 David Sulc 的书 Backbone Marionette:A Gentle Introduction,它使用以下代码片段向应用程序添加区域。
下面的示例使用 addRegions,我应该怎么做?
即
var ContactManager = new Marionette.Application({});
ContactManager.addRegions({
mainRegion: "#main-region"
});
var ContactView = Marionette.ItemView.extend({
template: "#whatever",
ui: {
button: ".button".
},
events: {
"click @ui.button": "click",
},
click: function () {
console.log("do stuff here...");
}
});
ContactManager.on("start", function () {
var contactView = new ContactView({
model: someModel
});
ContactManager.mainRegion.show(contactView);
});
改用布局视图。
例如您可以这样做:
var ContactManager = new Marionette.Application({});
var LayoutView = Backbone.Marionette.LayoutView.extend({
template: "#layout-view-template",
regions: {
menu: "#menu",
content: "#content"
}
});
ContactManager.layout_view = new LayoutView();
ContactManager.layout_view.render();
我从来没有直接将区域添加到我的应用程序对象。