2

我正在尝试创建一个子控制器来限制要检索的文章数量。这个想法是有这样的东西:

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;

模型/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;

模型/home-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"}}

模板/home/sections.hbs

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

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

非常感谢,

H

更新:

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

4

0 回答 0