我有一个EmberJS应用程序。我想做一个像全局变量/函数的东西,它会检测用户是从桌面计算机还是从移动设备访问应用程序。 在主控制器(控制器/的application.js)我有一个这样的代码:从run.schedule获取控制器var
Ember.Controller.extend({
currentUser: 0,
lastRemoteId: 0
})
我需要添加一个变量或函数是这样的:
Ember.Controller.extend({
...,
isMobile: function(){
[code which detects if user visited from mobile device or not]
}
})
在主视图(视图/应用.js)在didInsertElement里面我想得到这个isMobile var。当我尝试执行this.controllerFor('application')
时,我收到一个错误:“未定义不是函数”。像我这样做是否正确?