,除非這實際上是怎麼打破它
那什麼是真正打破它。綁定僅適用於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