javascript - wtat的getRegion和showChildView的区别

标签 javascript backbone.js marionette

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();

这段代码中的两个方法 getRegionshowChildView 有什么区别?

最佳答案

这只是一个快捷语法,来自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());

code behind showChildView

showChildView(name, view, ...args) {
    const region = this.getRegion(name);
    return region.show(view, ...args);
}

关于javascript - wtat的getRegion和showChildView的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40616111/

相关文章:

javascript - 为什么在 JavaScript 中使用 "with"关键字?

javascript - 鼠标悬停在d3.js中,如何获取相应位置的值?

javascript - Marionette.js 行为可以触发事件吗?

javascript - Backbone.历史和文件下载

javascript - WebSocket 连接到 'wss://localhost:44300/Home/websocketcon' 失败 : Error during WebSocket handshake: Unexpected response code: 404

javascript - 添加了变量值但数组没有被推送

javascript - Backbone JS : How to cascade Model#destroy?

javascript - CoffeeScript/Backbone/Marionette - 教程示例转换和范围界定问题

javascript - 编写鼠标悬停后 700 毫秒出现的按钮工具提示

javascript - Backbone 获取以获取集合