Backbone.Marionette 中项目视图和布局中的额外 div [英] Extra divs in itemviews and layouts in Backbone.Marionette

查看:19
本文介绍了Backbone.Marionette 中项目视图和布局中的额外 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 Backbone.Marionette,但我很困惑为什么我的布局和 ItemViews 不断生成额外的 div.

顺便说一句,例子是在咖啡中.

AppLayout = Backbone.Marionette.Layout.extend模板:#my-layout",地区:菜单:#menu",内容:#内容"MyMenuView = Backbone.Marionette.ItemView.extend模板:'#project_wiz_nav_template'MyContentView = Backbone.Marionette.ItemView.extend模板:'#project_setup_template'MyApp = new Backbone.Marionette.Application()MyApp.addRegionsmainRegion: '#project'MyApp.addInitializer ->布局 = 新 AppLayout()MyApp.mainRegion.show(布局)layout.menu.show(new MyMenuView())layout.content.show(new MyContentView())MyApp.start()

这是 index.html 包含的内容:

<script type='text/template' id='project_wiz_nav_template'><h2>HI</h2><script type='text/template' id='project_setup_template'><h2>世界</h2><script id="my-layout" type="text/template"><h2>你好!</h2><div id="菜单"></div><div id="内容"></div>

这是它产生的:

<div><h2>你好!</h2><div id="菜单"><div><h2>HI</h2>

<div id="内容"><div><h2>世界</h2>

如您所见,它不断为视图和布局生成额外的 div.我尝试添加 el: '#menu'el: '#content' 无济于事.

解决方案

这不是因为 Marionette.Backbone 默认为你生成一个

类.您可以通过 tagName 属性设置标签.请参阅对该问题的评论以获取重复项.

I am trying out Backbone.Marionette and I am confused as to why my Layouts and ItemViews keep generating extra divs.

example is in Coffee btw.

AppLayout = Backbone.Marionette.Layout.extend
  template: "#my-layout",

  regions:
    menu: "#menu",
    content: "#content"

MyMenuView = Backbone.Marionette.ItemView.extend
  template: '#project_wiz_nav_template'

MyContentView = Backbone.Marionette.ItemView.extend
  template: '#project_setup_template'

MyApp = new Backbone.Marionette.Application()

MyApp.addRegions
  mainRegion: '#project'

MyApp.addInitializer ->
  layout = new AppLayout()
  MyApp.mainRegion.show(layout)

  layout.menu.show(new MyMenuView())
  layout.content.show(new MyContentView())

MyApp.start()

This is what index.html contains:

<div id='project'></div>
<script type='text/template' id='project_wiz_nav_template'> <h2>HI</h2> </script>
<script type='text/template' id='project_setup_template'> <h2>WORLD</h2> </script>
<script id="my-layout" type="text/template">
  <h2>Hello!</h2>
  <div id="menu"></div>
  <div id="content"></div>
</script>

This is what it produces:

<div id="project">
  <div>
    <h2>Hello!</h2>
    <div id="menu">
      <div> 
        <h2>HI</h2> 
      </div>
    </div>
    <div id="content">
      <div> 
        <h2>WORLD</h2> 
      </div>
    </div>
  </div>
</div>

As you can see, it keeps generating extra divs for the views and the layouts. I've tried adding el: '#menu' and el: '#content' to no avail.

解决方案

This is not because of Marionette. Backbone generates a <div> class for you by default. You can set the tag via the tagName attribute. See comments on the question for duplicates of this.

这篇关于Backbone.Marionette 中项目视图和布局中的额外 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆