在Ember.js Handlebars模板中,有没有静态和动态类属性的方法? [英] In an Ember.js Handlebars template, is there a way to have both static and dynamic class attributes?

查看:226
本文介绍了在Ember.js Handlebars模板中,有没有静态和动态类属性的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用已经被过度使用的应用程序示例,假设我想要一个包含todo类(静态)和is-done类(动态)的元素:

Using the already-overused to-do app example, let's say I want an element with a "todo" class (static) and an "is-done" class (dynamic):

<div {{bindAttr class="todo isDone"}}>
  Other stuff in here
</div>

在这种情况下,isDone和todo都预期是我的视图对象的属性,这是我想要的isDone,而不是todo。我正在通过在我的视图上添加一个等于静态todo字符串的todo属性来解决这个问题。使用bindAttr有什么办法可以使用静态类属性吗?

In this case, "isDone" and "todo" are both expected to be properties on my view object, which is what I want for "isDone", but not for "todo". I'm currently working around this by adding a "todo" property on my view that is equal to a static "todo" string. Is there any way to have a static class attribute when using bindAttr?

小提示示例: http://jsfiddle.net/nes4H/4/

推荐答案

编辑:

我们已经在Ember中修复了这个问题!

We've fixed this in Ember!

在主版本的构建或0.9.6之后发布,你现在可以做:

On a build from master, or after 0.9.6 is released, you can now do:

< div {{bindAttr class =App.foo:a-bound-class:a- static-class}}>< / div>

答案:

使用 bindAttr 时,您不幸可以同时拥有静态和动态类名称。

You unfortunately can't have both static and dynamic class names when using bindAttr.

我建议您在视图中使用一个或多个计算属性来输出静态和动态类名。

I suggest using one or more computed properties on your view to output both static and dynamic class names.

支持静态和动态类名将是非常好的,但是 bindAttr 目前的工作方式,这是不可能的。 bindAttr 在模板编译期间不了解其附加元素的任何内容。

Supporting both static and dynamic class names would be very nice, but the way bindAttr currently works, it's not possible. bindAttr doesn't know anything about the element it's being attached to during template compilation.

这篇关于在Ember.js Handlebars模板中,有没有静态和动态类属性的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆