,除非这实际上是怎么打破它
那什么是真正打破它。绑定仅适用于Ember对象。 window
不是Ember对象。还有的路径是错误的问题,这里有一个图:
if isTrueBinding is "appController.isTrue", This will:
this won't work
+--------------+ +--------------+
| | | |
+-------+| window |+-----+ | window |
| | | | | |
| +--------------+ | +--------------+
v v +
+---------------+ +--------------+ |
| appController | | mod | |
|---------------| |--------------| v
| isTrue | |isTrueBinding | +--------------+
| | | | | mod |
| | | | |--------------|
| | | | |isTrueBinding |
| | | | |appController |+---> +---------------+
| | | | | | | appController |
| | | | | | |---------------|
| | | | | | | isTrue |
+---------------+ +--------------+ | | | |
| | | |
| | | |
+--------------+ | |
| |
| |
i.e. bindings are implicitly pointing to "this", | |
unless they start with a capital letter. +---------------+
当绑定做一个大写字母开头,则是指一个全局对象,如:
window.Currency = Em.Object.create({
"USD": "$"
});
App.MyObject = Em.Object.extend({
currencyBinding: "Currency.USD"
});
然而,使用绑定绑定到全局对象在Ember中被认为不是很好的样式 - 最好的做法是使用依赖注入来访问共享对象。如果你发现自己需要使用全局绑定,这可能是你需要重构的一个标志。
但appController是一个烬对象?我没有约束窗口 – FellowMD
的属性,实际上这甚至不是唯一被破坏的东西。绑定是相对于你声明它们的对象。所以你绑定到'appController.isTrue'指向window.mod.appController.isTrue,而你想要的属性是在window.appController.isTrue。即使你可以通过窗口对象绑定(你不能),它不会工作,因为路径是错误的 – alexspeller
http://emberjs.com/guides/object-model/bindings/似乎暗示它是一个全球性的路径 – FellowMD