2013-07-23 5 views
1

Я хотел бы получить контроллер с другого контроллера.
получить один контроллер от другого контроллера с emberjs

App определить

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 }; 
    } 
}); 

контроллер определяют

App.MarketsSourcesController = Ember.ObjectController.extend({ 
    need: ['nav'], 
    testmethod: function(){ 
     this.get("content").clear(); 
    } 
}); 

App.MarketsController = Ember.ObjectController.extend({ 
    test:function(){ 
     //****************************************// 
      MAIN AREA 
     //****************************************// 
    } 
}); 

Я буду называть TestMethod() из App.MarketsController в тесте() из приложения .MarketsController.
Для этого я использовал this.controllerFor() и this.get()
Но эти доцентные работы. Хотелось бы этого.

ответ

2

Используйте 'needs' для использования одного контроллера внутри другого контроллера.

App.MarketsController = Ember.ObjectController.extend({ 
needs: ['marketsSources'], 
test:function(){ 
    this.get('controllers.marketsSources').testmethod(); 
} 
}); 
Смежные вопросы