2013-07-23 207 views
1

我想從另一個控制器獲取控制器。
從另一個控制器從emberjs獲得一個控制器

應用程序定義

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

我會在測試應用程序的App.MarketsController的調用TestMethod的()() .MarketsController。
對此,我已經使用this.controllerFor()和this.get()
但這些dosent工作。 我想要。

回答

2

使用「需要」在另一個控制器內部使用一個控制器。

App.MarketsController = Ember.ObjectController.extend({ 
needs: ['marketsSources'], 
test:function(){ 
    this.get('controllers.marketsSources').testmethod(); 
} 
}); 
相關問題