I want to use this.get('controllers.pack.query');
to get
App.PackQueryController
in App.PackController
, but failed.
I think the problem is Ember use pack
not pack.query
as controllerName
when it tries to get the controller.
Although I can get the controller by this.controllerFor('pack.query')
,
but Ember says it is deprecated, please use needs
instead
My router map likes below and I've defined needs: ['pack.query']
in 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
}
});