1
我是Ember.js的新手。我在我的HTML如下實驗:使用Ember.js在Javascript中更新DOM中的值
<p>Username: {{view Ember.TextField valueBinding="MyApp.loginController.bound.username" id="view-login-username" placeholder="Your username"}}</p>
The username field is: {{MyApp.loginController.bound.username}}
{{#view Ember.Button
classBinding="isActive"
target="MyApp.loginController"
action="submitLogin"}}
Login {{/view}}
在我的Javascript我有以下幾點:
MyApp = SC.Application.create();
MyApp.loginController = Ember.Object.create({
bound : { username:'12345' },
submitLogin: function() {
MyApp.loginController.bound.username = "abcdef";
alert(MyApp.loginController.bound.username);
}
});
當我把我的「登錄」按鈕,更改爲「ABCDEF」不會出現在DOM中,也不在緊接賦值之後的alert()中。警報出現但仍顯示「12345」。
我錯過了什麼?
謝謝!
完美。我其實也嘗試過set(),但那不起作用。那麼setPath()就是!謝謝! – shs 2012-03-23 18:57:32
get/set是當前對象的屬性。當你需要一個嵌套的屬性時使用getPath/setPath。 – 2012-03-23 20:41:55