【发布时间】:2014-10-01 13:17:45
【问题描述】:
我有一个 EmberJS 应用程序。我想做一个像全局变量/函数这样的东西,它可以检测用户是从台式计算机还是从移动设备访问应用程序。 在主控制器 (controller/application.js) 我有这样的代码:
Ember.Controller.extend({
currentUser: 0,
lastRemoteId: 0
})
我需要像这样添加一个变量或函数:
Ember.Controller.extend({
...,
isMobile: function(){
[code which detects if user visited from mobile device or not]
}
})
在didInsertElement 的主视图(views/application.js)中,我想得到这个isMobile var。当我尝试执行 this.controllerFor('application') 时收到错误消息:“未定义不是函数”。像我做的那样正确吗?
【问题讨论】:
标签: javascript jquery ember.js