在灰烬

问题描述:

从观察者呼叫控制器内的功能我有这样在灰烬

App.TestController = Ember.ArrayController.extend({ 
    navigation:[], 
    somefunc:function(){ 
     //do something 
    } 
}); 

控制器和有

globalvars = Ember.Object.create({ 
    page : 1, 
}); 

globalvars.addObserver('page', function() { 
    this.get('controller.controllers.Test').somefunc(); 
}); 

问题的观察者是,我不能把里面的功能控制器。

+0

我不知道是否还有其他错误,但在'this.get('controller.controllers.Test')。somefunc();''test“需要小写,我想。 – 2013-04-04 11:03:16

+0

TypeError:this.get(...)未定义 [Break On This Error] \t this.get('controller.controllers.test')。somefunc();我得到这个错误 – Fahim 2013-04-04 11:27:09

+0

你应该更详细地解释你正在努力完成什么。您试图以奇怪的方式访问控制器。并非每个Ember对象都必须访问每个控制器。你的方法无法工作。 – mavilein 2013-04-04 11:36:55

正如我在我的评论已经提到的,在这里免责声明:

You should explain in more detail, what you are trying to accomplish. You are trying to access the controller in a strange way.

但在这里是一种方法,如果你绝对要做到这一点是这样的:

var App = Ember.Application.create({}); 
// put the global vars into the App object instead of polluting the global namespace 
App.globalvars = Ember.Object.create({ 
    page : 1, 
}); 

而不是把观察员在globalVars对象中,我会在控制器中声明观察者:

App.TestController = Ember.ArrayController.extend({ 
    navigation:[], 
    somefunc:function(){ 
     //do something 
    }, 
    globalVarsPageObserver : function(){ 
     this.somefunc(); 
    }.observes("App.globalvars.page") 
});