小编Isa*_*ddo的帖子

Ember.js如何获得需要的控制器,它是嵌套的controllerName

我想用this.get('controllers.pack.query');得到 App.PackQueryControllerApp.PackController,但失败了.

我认为这个问题是灰烬使用pack不是pack.query因为controllerName 当它试图获取控制.虽然我可以得到控制器this.controllerFor('pack.query'),但是Ember说它已被弃用,请needs改为使用

我的路由器地图喜欢下面,我已经定义needs: ['pack.query']App.PackController

App.Router.map(function () {
    this.resource('pack', function () {
        this.route('index', {path: '/:pack_id'})
        this.route('query');
    });
});

App.PackController = Ember.ObjectController.extend({
    needs: ['pack.query'],
    queryPack: function () {
        var packQueryCtrller = this.get('controllers.pack.query');            

        Ember.debug('packQueryCtrller: ' + packQueryCtrller);
        //DEBUG: packQueryCtrller: undefined

        packQueryCtrller.queryPack(); //faild packQuery is undefined
    }
});

App.PackQueryController = Ember.ArrayController.extend({
    queryPack: function (queryKey) {
        //...do query pack
    }
});
Run Code Online (Sandbox Code Playgroud)

controller nested-routes ember.js

15
推荐指数
2
解决办法
7418
查看次数

标签 统计

controller ×1

ember.js ×1

nested-routes ×1