How to attach Backbone.Marionette view to existing element without creating extra element

故事扮演 提交于 2019-12-21 04:27:18

问题


Say I have these two Backbone.Marionette views:

var FooView = Backbone.Marionette.ItemView.extend({
  tagName: p,
  id: 'foo',
  template: this.templates.summary
});

var BarView = Backbone.Marionette.ItemView.extend({
  template: this.templates.summary
});

And then I want to show them inside an app region, like so:

App.contentRegion.show(new FooView/BarView());

The first view would create a new

element and append it to the region. I thought the second way would be more like a standard Backbone view and attach itself to the region without creating a new element, but it wraps it in a tag. Is there a way to avoid this without using something like setElement()?


回答1:


For this, you should use the attachView method: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.region.md#call-attachview-on-region



来源:https://stackoverflow.com/questions/18117082/how-to-attach-backbone-marionette-view-to-existing-element-without-creating-extr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!