我在使用emberjs时遇到麻烦.我已将ember textfield绑定到控制器内的变量.当我写入文本字段时,绑定变量会正确更新.
现在我想通过JS更改变量(以及文本字段中的文本).我什么都没发生.
App = Ember.Application.create({});
App.FormInfo = Em.TextField.extend({
insertNewline: function(){
App.AController.clear();
}
});
App.AController = Em.ArrayController.create({
content: [],
name: '',
clear: function(){ //I want this function to clear the text field and set name to an empty string
this.name = '';
console.log(this.name);//expected empty string; actual user input
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.5.min.js"></script>
<script type="text/x-handlebars">
{{view App.FormInfo placeholder="Name" valueBinding="App.AController.name"}}
</script>Run Code Online (Sandbox Code Playgroud)
ember.js ×1