CSS 用于 ember 查看标签

CSS for ember view tag

我想在视图 class 中为 ember 视图设置 z-index,但 ember 一直抛出错误:

DEPRECATION: Dynamic content in the `style` attribute is not escaped and may pose a security risk.

我的 class 的缩略版是这样的:

App.ModalComponent = Ember.Component.extend({
    layoutName: 'components/modal',
    classNames: ['modal', 'fade'],
    attributeBindings: ['style'],
    style: function() {
        return 'z-index:131071';
    }.property()
});

有经验丰富的 ember 专家知道在 Ember 视图上设置自定义样式的更合适方法吗?谢谢!

这个 "deprecation" 似乎是 Ember 的最新版本中添加的新内容。就个人而言,我宁愿称它为 "warning",但无论如何。

解决方法是安全串起来:

style: function() {
    return new Ember.Handlebars.SafeString('z-index: 131071');
}.property()  

或者,您可以只添加具有适当 属性 设置的 class。

在 HTMLBars 中,您将能够编写

<div style="z-index: {{zIndex}}"> .... </div>

有关详细信息,请参阅 this post. But I'm not sure this syntax is currently supported. A report on this is here