Emberjs loading multiple controllers into one

前端 未结 2 1078
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 17:29

SCENARIO
I currently have an IndexRoute. I want to load 3 other controllers into it. Those 3 other controllers are called Sports

2条回答
  •  北海茫月
    2021-01-15 17:55

    route's are only hit when you define and hit a route via url.

    For example if you'd defined your router like this:

    Ember.Router.map(function(){
      this.resource('foo', function(){
        this.resource('bar');
      });
    });
    

    And hit /foo/bar

    It would hit

    App.FooRoute = Em.Route.extend({
    
    });
    

    and

    App.BarRoute = Em.Route.extend({
    
    });
    

    If you want to hit it all from just the root url you might as well return it all from the application model hook.

    App.ApplicationRoute = Ember.Route.extend({
      model: function() {
        return {
          colors: ['red', 'yellow', 'blue'],
          news: ['Europe', 'Asia', 'America'],
          business: ['Markets', 'Finance', 'Stocks'],
          sports: ['golf', 'hockey', 'football']
        };
      }  
    });
    

    And then you can use render from the template and supply it a template name and a model.

    
    

    http://jsbin.com/gecarido/3/edit

提交回复
热议问题