wtat的getRegion和showChildView的区别
Wtat's differences between getRegion and showChildView
const template1 = _.template('<h1>Marionette says hello!</h1>');
const template2 = _.template('<h1>Marionette is awesome!</h1>');
const myView1 = new Mn.View({template: template1});
const myView2 = new Mn.View({template: template2});
const MyView = Mn.View.extend({
el: '#container',
template: false,
regions: {
region1: '#region1',
region2: '#region2'
},
onRender() {
this.getRegion('region1').show(myView1);
this.showChildView('region2', myView2);
}
});
const myView = new MyView();
myView.render();
这段代码 getRegion
和 showChildView
中的两种方法有什么区别?
这只是一个快捷语法,来自Marionette doc:
layoutView.getRegion('menu').show(new MenuView());
layoutView.getRegion('content').show(new MainContentView());
There are also helpful shortcuts for more concise syntax.
layoutView.showChildView('menu', new MenuView());
layoutView.showChildView('content', new MainContentView());
showChildView(name, view, ...args) {
const region = this.getRegion(name);
return region.show(view, ...args);
}
const template1 = _.template('<h1>Marionette says hello!</h1>');
const template2 = _.template('<h1>Marionette is awesome!</h1>');
const myView1 = new Mn.View({template: template1});
const myView2 = new Mn.View({template: template2});
const MyView = Mn.View.extend({
el: '#container',
template: false,
regions: {
region1: '#region1',
region2: '#region2'
},
onRender() {
this.getRegion('region1').show(myView1);
this.showChildView('region2', myView2);
}
});
const myView = new MyView();
myView.render();
这段代码 getRegion
和 showChildView
中的两种方法有什么区别?
这只是一个快捷语法,来自Marionette doc:
layoutView.getRegion('menu').show(new MenuView()); layoutView.getRegion('content').show(new MainContentView());
There are also helpful shortcuts for more concise syntax.
layoutView.showChildView('menu', new MenuView()); layoutView.showChildView('content', new MainContentView());
showChildView(name, view, ...args) { const region = this.getRegion(name); return region.show(view, ...args); }