简体   繁体   English

没有div包装的Ember模板

[英]Ember template without div wrapper

Semantic UI (a HTML5 component library) provides the Sitebar component, which needs a specific page structure directly below <body> . 语义UI(HTML5组件库)提供Sitebar组件,它需要在<body>正下方的特定页面结构。

Since Ember introduced HTMLBars, it wraps all templates' content within another <div> tag before injecting it into the DOM, eg 由于Ember引入了HTMLBars,它将所有模板的内容包装在另一个<div>标签中,然后将其注入DOM,例如

<div id="ember389" class="ember-view"><!-- original template's content comes here --></div>

which makes using the above mentioned Sitebar and comparable components virtually unusable. 这使得使用上述Sitebar和类似组件几乎无法使用。

There have been similar questions for older Ember versions, but their answers do not work anymore, as Views have been retired. 对于较旧的Ember版本,也存在类似的问题,但由于Views已经退役,因此它们的答案不再适用。 Ember still provides the private _MetamorphView class for "templates without wrappers", but besides the fact that it is also deprecated, I don't now how to incorporate them into my Route . Ember仍为“没有包装器的模板”提供私有_MetamorphView类,但除了它也被弃用之外,我现在还不知道如何将它们合并到我的Route

Any help is greatly appreciated! 任何帮助是极大的赞赏!

It's actually not that much hard as you think. 它实际上并没有你想象的那么难。 All you need is to make some slight changes in the component . 您只需要在组件中进行一些细微的更改。 (Assume you're using Ember 2.x and want to make side bar as component) (假设您正在使用Ember 2.x并希望将侧栏作为组件)

For Eg. 对于Eg。

// app/components/side-bar.js
export default Ember.Component.extend({
    classNames: ['ui', 'sidebar']
});

// app/templates/components/side-bar.hbs
{{yield}}

// usage 
// app/templates/application.hbs
{{#side-bar}}
    // your sidebar contents go here
{{/side-bar}}
<div class="pusher">
    // Your site's actual content
    {{outlet}}
</div>

If the side bar isn't necessary to be a component, then it'll be lot simpler 如果侧栏不是必须的组件,那么它会简单得多

// app/templates/application.hbs
<div class="ui sidebar">
  // ...
</div>
<div class="pusher">
  // Your site's actual content
  {{outlet}}
</div>

EDIT - answer to the comment 编辑 - 回答评论

A sidebar can be initialized inside any element, not just a page's body. 侧边栏可以在任何元素内初始化,而不仅仅是页面的主体。

http://semantic-ui.com/modules/sidebar.html#using-a-custom-context http://semantic-ui.com/modules/sidebar.html#using-a-custom-context

You can use the following: 您可以使用以下内容:

 import Ember from 'ember'; export default Ember.Component.extend({ /** * No default div around the element. */ tagName: '' }); 

在.hbs中设置空tagName参数

{{component-name tagName=''}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS-如何在没有包装的情况下包含模板 - AngularJS - how to include a template without a wrapper Vue:模板不能键入,但不能用 div 替换模板 - 需要没有包装 div 元素的 v-for,嵌套的 v-for 循环 - Vue: template can't be keyed, but can't replace template with div - need the v-for without a wrapper div element, nested v-for loops Bootstrap:如何在不跳跃的情况下折叠包装div? - Bootstrap: How to collapse a wrapper div without jumping? 如何在不克隆包装器的情况下克隆div - How to .Clone div without cloning the wrapper div底部没有包装的位置图像 - position image at bottom of div without wrapper 在没有 ID 或 class 的 div 周围插入包装器 - Insert wrapper around div without an ID or class 删除没有Jquery的包装div(原始javascript) - Removing wrapper div without Jquery (raw javascript) 是否在没有Ember应用程序的情况下编译Ember模板字符串并以编程方式运行它? - Compile Ember template string and running it programmatically, without an Ember application? 如何删除包装div或将其类型从div更改为ember-from-for中的span? - How can I remove the wrapper div or change its type from div to span within ember-from-for? 如何在没有包装的情况下将Backbone.View.el绑定到模板? - How to bind Backbone.View.el to a template without a wrapper?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM