应用程序开始时绑定到属性 [英] Binding to Attributes when Application Starts

查看:110
本文介绍了应用程序开始时绑定到属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序首次启动并加载应用程序视图时,我尝试绑定到布尔属性,以便有条件地设置CSS类。布尔属性被正确初始化,但不设置类。启动后绑定似乎工作正常。以下是一个JSFiddle,演示了问题。任何想法为什么首次运行失败?

When my application first starts up and the application view loads, I attempt to bind to boolean attributes in order to conditionally set a CSS class. The boolean attributes are initialized properly but the class does not get set. The binding seems to work fine after the startup. Here is a JSFiddle that demonstrates the issue. Any ideas why this fails the first-time it runs?

推荐答案

我从GitHub的ember.js团队收到了一个答案。

I received an answer from the ember.js team on GitHub.

这是Kristofor Selden的回应...

Here's the response from Kristofor Selden...


您的模板输出2类属性,当jQuery将其导入到DOM中时,它将删除>后者,它不会合并它们。之后绑定更新DOM中的属性。
如果你想要一个静态类和一个绑定类,你需要把静态类放在
bindAttr帮助器中,
{{bindAttr class =:something isB:redbg:greenbg}}

Your template outputs 2 class attributes, and when jQuery brings it into DOM it removes the > latter, it does not merge them. After that the binding updates the attribute in DOM. If you want a static class and a bound class you need to put the static class in the bindAttr helper with {{bindAttr class=":something isB:redbg:greenbg"}}

http://jsfiddle.net/krisselden / uWJWh / 9 /

这篇关于应用程序开始时绑定到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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