像许多人(我认为)一样,将样式属性绑定(bind)到模板中的元素时,我会在控制台中收到警告。
例如,我有一个 ember View ,其中包含一个具有以下样式属性的 div:
style="{{view.isClosing}};"
现在,我收到警告,该字符串未正确转义,可能会使其容易受到 XSS 攻击。
我访问了此链接:http://emberjs.com/deprecations/v1.x/#toc_warning-when-binding-style-attributes
然后尝试将其放入我的 View 中:
isClosing: Ember.computed('display', function () {
if (this.get('conv.isClosing')) {
return new Ember.Handlebars.SafeString("display:");
} else {
return new Ember.Handlebars.SafeString("display: " + this.get('display'));
};
}),
警告并没有消失,当我尝试使用文档中所说的函数 escapeCSS 来执行此操作时,它告诉我 escapeCSS 未定义。现在这个功能是什么?我应该怎么做?
谢谢
最佳答案
如 this blog post 中所述,您想使用 Ember.String.htmlSafe
而不是 Ember.Handlebars.SafeString
。
isClosing: Ember.computed('display', function () {
if (this.get('conv.isClosing')) {
return new Ember.String.htmlSafe("display:");
} else {
return new Ember.String.htmlSafe("display: " + this.get('display'));
};
}),
关于ember.js - 使用 ember JS 转义 CSS 字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289755/