尝试将视图中的值绑定到控制器中的值时,我遇到了一些单向绑定问题:
App.ApplicationController = Ember.Controller.extend({
value: 'my value'
});
App.ApplicationView = Ember.View.extend({
templateName: 'application',
willInsertElement: function() {
console.log('will insert element');
console.log('value from controller > ', this.get('controller').get('value'));
console.log('value > ', this.get('value'));
console.log('completeValue > ', this.get('completeValue'));
},
valueBinding: Ember.Binding.oneWay('controller.value'),
completeValueBinding: Ember.Binding.oneWay('App.ApplicationController.value')
});
“值>”返回正确的值,但“completeValue>”返回undefined(参见jsFiddle http://jsfiddle.net/U29wV/7/)...
答案 0 :(得分:0)
您引用的是类ApplicationController
,而不是实际的实例。
您已经通过视图的ApplicationController
属性访问controller
实例,因此只需将其用于绑定:
valueBinding: Ember.Binding.oneWay('controller.value'),
completeValueBinding: Ember.Binding.oneWay('controller.value')
这使它与valueBinding
...