在骨干网和木偶额外包装 [英] Extra wrappers in Backbone and Marionette

查看:138
本文介绍了在骨干网和木偶额外包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用骨干网和提线木偶,我创建了一个新的布局,进入我的页面上的主要内容股利。布局是这样的:

Using Backbone and Marionette, I've created a new layout that goes into the main content div on my page. The layout looks like this:

<div id='dash-sidebar'>
    <div id='dash-profile'></div>
    <div id='dash-nav'></div> 
</div>
<div id='dash-content'></div>

问题是,当我呈现布局,骨干会自动把它包装在一个div把它变成主要内容的div像这样前:

The issue is that when I render the layout, Backbone automatically wraps it in a div before putting it into the main content div like this:

<div id='main-content'>    
  <div>
    <div id='dash-sidebar'>
      <div id='dash-profile'></div>
       <div id='dash-nav'></div> 
    </div>
    <div id='dash-content'></div>
  </div>
</div>

我知道我可以改变标记名的元素,但有可能完全避免包装模板,只需直接插入到页面?

I know that I can change the element with tagName, but is it possible to avoid wrapping the template altogether and just insert it directly into the main content div on the page?

推荐答案

每个主干查看必须重新$ P $由一个单一的元素psented。你的第一个HTML块有两个元素,这就是为什么它不能被重新被认为psented $ P $没有在外层div第一包装它。

Each Backbone View must be represented by a single element. Your first HTML block has two elements, which is why it cannot be represented by a view without first wrapping it in an outer div.

你能重构布局包含主要内容区域呢?然后布局的将对应于整个外层div。

Could you refactor your Layout to include the main-content area as well? Then the Layout's el would correspond to the entire outer div.

另一件事,试图将使用Backbone.View的 setElement()方法重写的创建外层div,并手动注入你想在一个视图元素的HTML。是这样的:

Another thing to try would be using Backbone.View's setElement() method to override the creation of the outer div, and manually inject the HTML that you want for the element in a View. Something like:

onRender: function() {
    this.setElement( /* the HTML you want for your layout */ );
}

我不知道怎么样,如果你HTML中有刚一二父元素,而不是通过这会工作,但是。

I'm not sure how this would work if you passed in HTML that had two parent elements instead of just one, however.

这篇关于在骨干网和木偶额外包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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