简体   繁体   English

EmberJS-在路由setupController中调用控制器方法

[英]EmberJS - Calling a controller method within a routes setupController

I have a controller with a few methods attached to it. 我有一个附带一些方法的控制器 I have a relevant route . 我有一条相关路线 I added the methods inside the controller so that they can be re-used in a few other places. 我在控制器中添加了方法,以便可以在其他一些地方重用它们。 These methods retrieve some data from the server. 这些方法从服务器检索一些数据。 Inside the setupController of the route, I'm calling these methods and everything works as expected. 在路由的setupController内部,我正在调用这些方法,并且一切正常。

But once I concatenate the files, Ember throws an error saying the method I'm trying to call is undefined. 但是,一旦我串联了文件,Ember就会抛出一个错误,说我要调用的方法是不确定的。 I use grunt-contrib-concat plugin but also tried changing it to use uglify . 我使用grunt-contrib-concat插件,但也尝试将其更改为使用uglify Still the same issue. 还是一样的问题。 I don't think there is anything wrong with the concatenation as it always worked previously. 我不认为串联有什么问题,因为它以前一直有效。 However, I never used the setupController before other than to set properties. 但是,除了设置属性外,我从未使用过setupController。 Added the sample code below. 在下面添加了示例代码。 Any help is appreciated. 任何帮助表示赞赏。

/*  Ember 1.10.0 Debug version */

/* Route */
App.DashboardRoute = Ember.Route.extend({
    model: function() { return []; },
    setupController: function(controller, model) {
        this._super(controller, model);

        /* Setting values on the controller works */
        controller.set('currentDate', new Date());

        /* Calling a method works normally but throws error when minified */
        /* Error: dashboard undefined is not a function */
        controller.addNumbers();
    }        
});

/* Controller */
App.DashboardController = Ember.ArrayController.extend({
    currentDate: null,
    addNumbers: function() {
        return 1 + 2;
    }
});

I would say you need to look at the minified code or the order that the code is being concatendated, but it's not a problem with setupController . 我要说的是,您需要查看压缩后的代码或代码被并置的顺序,但这不是setupController的问题。

I created a JSbin with your example and run it through Uglify, and it works correctly. 我用您的示例创建了一个JSbin并通过Uglify运行它,它可以正常工作。

http://emberjs.jsbin.com/mizudelupi/2/ http://emberjs.jsbin.com/mizudelupi/2/

If you can create a JSbin with your minified, concatendated code, we can take a look and help. 如果您可以使用紧凑的代码创建一个JSbin,我们可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM