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
中的两种方法之间存在哪些差异?
答案 0 :(得分:4)
这只是Marionette doc:
的快捷语法layoutView.getRegion('menu').show(new MenuView()); layoutView.getRegion('content').show(new MainContentView());
还有一些有用的快捷方式可以提供更简洁的语法。
layoutView.showChildView('menu', new MenuView()); layoutView.showChildView('content', new MainContentView());
showChildView(name, view, ...args) { const region = this.getRegion(name); return region.show(view, ...args); }