2013-02-27 55 views
0

我有一些单向绑定问题,而试图在我看来,一个值绑定到在我的控制器值:ember.js单向绑定

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

什么'valueBinding'和'completeValueBinding'之间的区别? – CraigTeegarden 2013-02-27 17:55:57

回答

0

您正在引用类ApplicationController而不是实际的实例。

您已经通过您的视图的controller属性访问ApplicationController实例,所以只需要使用的绑定:

valueBinding: Ember.Binding.oneWay('controller.value'), 
completeValueBinding: Ember.Binding.oneWay('controller.value') 

这使得它等同于valueBinding ...