Ember.js 文本字段的Ember单向绑定
如何创建可以写入模型但不从模型读取的视图。基本上是单向绑定 我有一个粗略的尝试,但这不是一个很好的解决方案,也不起作用Ember.js 文本字段的Ember单向绑定,ember.js,Ember.js,如何创建可以写入模型但不从模型读取的视图。基本上是单向绑定 我有一个粗略的尝试,但这不是一个很好的解决方案,也不起作用 App = Ember.Application.create(); App.NewTextField = Ember.TextField.extend({ focusIn: function() { this.valueBinding = "comment"; }, focusOut: function() { this
App = Ember.Application.create();
App.NewTextField = Ember.TextField.extend({
focusIn: function() {
this.valueBinding = "comment";
},
focusOut: function() {
this.valueBinding = null;
}
});
看小提琴 通过绑定到textfield的值并观察它的变化,我找到了一个解决方案,我可以在控制器中更新模型
App.NewTextField = Ember.TextField.extend({
valueDidChange: function() {
value = this.get('value');
controller = this.get('targetObject');
controller.set('comment', value)
}.observes('value')
});
有效的解决方案就在这里。并不是说valueBinding已被删除。
但这并不完美。在更新时,我将无法清除文本字段