Ember.js创建一个没有路由的子控制器

时间:2014-04-25 16:30:32

标签: ember.js ember-cli

我试图创建一个子控制器来限制要检索的文章数量。我的想法就是拥有类似的东西:

var HomeSectionController = Ember.ObjectController.extend({
  selectedArticles: functioin(){
    // code here
  }.property('articles')
});

第一个使用Ember和Ember-CLI的真实项目,所以我还在消化这些概念。

到目前为止,这是看起来的样子:

模型/ home.js

var Home = DS.Model.extend({
  sections: DS.hasMany('homeSection', {async: true})
});

Home.reopenClass({
  FIXTURES: [
    {
      id: 1,
      sections: [1, 2]
    }
  ]
});

export default Home;

模型/家庭section.js

var HomeSection = DS.Model.extend({
  title: DS.attr('string')
});

HomeSection.reopenClass({
  FIXTURES: [
    {id: 1, title: 'About', articles: [1,2,3,4,5]},
    {id: 2, title: 'Contact'}
  ]
});

export default HomeSection;

模型/家庭article.js

var HomeArticle = DS.Model.extend({
  title: DS.attr('string')
});

HomeArticle.reopenClass({
  FIXTURES: [
    {id: 1, title: 'Article 1'},
    {id: 2, title: 'Article 2'},
    {id: 3, title: 'Article 3'},
    {id: 4, title: 'Article 4'},
    {id: 5, title: 'Article 5'},
  ]
});

export default HomeArticle;

路由/ home.js

export default Ember.Route.extend({
  model: function() {
    return this.store.find('home');
  }
});

模板/ home.hbs

{{partial "home/sections"}}

模板/家/ sections.hbs

{{#each model}}
<div class="sections">
  {{#each sections}}
    {{#each articles}}
     ... the magic happens here!
    {{/each}}
  {{/each}}
</div>
{{/each}}

我在哪里创建HomeSectionControllercontrollers/home-section.js是正确的命名结构吗?

非常感谢,

ħ

更新:

我的疑问是关于没有路线的儿童控制器,与ember-cli没有真正关系。无论如何,我在这里找到了一个很好的讨论http://discuss.emberjs.com/t/parent-child-controller-relationships-without-using-routes/761/19回答了我之前遇到的一些问题。

0 个答案:

没有答案
相关问题