How do I add classNames to the first element of the page without using a view?

时间:2015-09-01 21:16:42

标签: ember.js

I want to add a wrapper class to the first div element in my page. I used to do this with a view. So, it seems that Ember 2.0 won't support Views anymore. So how can I do that now?

view/application.js:

import Ember from 'ember';

export default Ember.View.extend({
    classNames: ['wrapper'],
});

Resulting in the following page:

<body class="ember-application">

<div id="ember573" class="ember-view wrapper">
    the rest of my page in this div
</div>

</body>

How is this done now that views are deprecated?

4 个答案:

答案 0 :(得分:7)

I used css to solve this problem:

body > .ember-view {
  padding-left: 240px; //styles for container goes here
}

答案 1 :(得分:6)

我没有一个简洁的解决方案,但是从Ember.Component内部对applications/view.js进行子类化工作。

https://ember-twiddle.com/b15411266f996191605c

答案 2 :(得分:1)

在ember 2.0中不推荐使用

Views。从现在开始做事的方法是使用componentroute。您可以通过执行以下操作来指定应用于组件的类名称:

export default Ember.Component.extend({
/* Wrap your component in primary class*/
  classNames: ['primary'],

/*defined class binding*/
  classNameBindings: ['isUrgent'],
  isUrgent: true
});

有关如何自定义component的所有信息都可以在ember文档中找到(click here to find out more

答案 3 :(得分:0)

您现在不应该使用Views,因为它们已被弃用。改为使用组件,例如:

import Ember from 'ember';

export default Ember.Component.extend({
    classNameBindings: ['functionName'],

    functionName: Ember.computed(function() {
        // function logic
    })
});