如何安装Backbone.Marionette以现有元素,而无需创建额外的元素 [英] How to attach Backbone.Marionette view to existing element without creating extra element

查看:111
本文介绍了如何安装Backbone.Marionette以现有元素,而无需创建额外的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这两个Backbone.Marionette观点:

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

第一种观点将创造一个新的

元素,并将其附加到该地区。我认为第二种方式会更像一个标准的骨干观点,重视自己的区域,而无需创建一个新的元素,但是它把它包装的标签。有没有办法避免这种情况,而无需使用类似setElement()?

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

推荐答案

对于这一点,你应该使用 attachView 方法:<一href=\"https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.region.md#call-attachview-on-region\">https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.region.md#call-attachview-on-region

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

这篇关于如何安装Backbone.Marionette以现有元素,而无需创建额外的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆