Emberjs将多个控制器加载到一个 [英] Emberjs loading multiple controllers into one

查看:60
本文介绍了Emberjs将多个控制器加载到一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景

我目前有一个 IndexRoute 。我想加载3个其他控制器。其他3个控制器称为体育新闻业务 。我阅读了embersjs文档,并声明您需要为每个这些控制器的 IndexRoute 中实现 renderTemplate 钩子在索引中显示。


SCENARIO
I currently have an IndexRoute. I want to load 3 other controllers into it. Those 3 other controllers are called Sports, News, Business. I read the embersjs documentation and it states that you need to implement the renderTemplate hook into the IndexRoute for each of those controllers to be shown in the index. http://emberjs.com/guides/routing/rendering-a-template/

Once I did that I put in the index template

{{ outlet sports }}
{{ outlet news }}
{{ outlet business }}

They are showing up but as I look through the EmberInspector extension the individual model for Sports, News, Business are not loading.

QUESTION
Why are the models for these Sports, News, Business not loading in the index?

SEE JSBIN for my code sample
http://jsbin.com/gecarido/1/edit

ATTACHED IMAGE

解决方案

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.

<script type="text/x-handlebars">
  <h2>Welcome to Ember.js</h2>

  <ul>
  {{#each item in colors}}
    <li>{{item}}</li>
  {{/each}}
  </ul>

  <br>
  {{render 'sports' sports}}
  <br>
  {{render 'news' news}}
  <br>
  {{render 'business' business}}
  <br>
  {{outlet}}
</script>

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

这篇关于Emberjs将多个控制器加载到一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆