我想从另一个控制器获取控制器。
App define
var App = Ember.Application.create();
App.Router.map(function() {
this.route("index", {path: "/"});
this.resource('markets', {path: "/markets"}, function() {
this.route("sources");
});
});
定义路线
App.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('markets');
}
});
App.MarketsRoute = Ember.Route.extend({
model: function () {
return App.Markets.find();
}
});
App.MarketsRoute = Ember.Route.extend({
model: function () {
return App.Markets.find();
}
});
App.MarketsSourcesRoute = Ember.Route.extend({
model: function(){
return App.Sources.find();
},
serialize: function(model) {
return { markets_id: model.id };
}
});
controller define
App.MarketsSourcesController = Ember.ObjectController.extend({
need: ['nav'],
testmethod: function(){
this.get("content").clear();
}
});
App.MarketsController = Ember.ObjectController.extend({
test:function(){
//****************************************//
MAIN AREA
//****************************************//
}
});
我将在App.MarketsController的test()中调用App.MarketsController的testmethod()。
为此,我使用了this.controllerFor()和this.get()
但那些有用的工作。
我想要它。
答案 0 :(得分:2)
使用'needs'在另一个控制器中使用一个控制器。
App.MarketsController = Ember.ObjectController.extend({
needs: ['marketsSources'],
test:function(){
this.get('controllers.marketsSources').testmethod();
}
});