Tôi muốn sử dụng this.get('controllers.pack.query');
để nhận App.PackQueryController
trong App.PackController
, nhưng không thành công.Ember.js Cách nhận bộ điều khiển theo nhu cầu mà được lồng vào controllerName
Tôi nghĩ vấn đề là Ember sử dụng pack
không pack.query
là controllerName
khi cố gắng lấy bộ điều khiển. Mặc dù tôi có thể nhận được điều khiển bởi this.controllerFor('pack.query')
, nhưng Ember nói nó bị phản đối, hãy sử dụng needs
thay
Bản đồ của tôi Router thích dưới đây và tôi đã xác định needs: ['pack.query']
trong 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
}
});
này không không làm việc bài ember-cli 0.2.3. Xem câu trả lời của @rog cho một giải pháp làm việc. –