Chunk Ember模型阵列

时间:2016-07-25 14:38:40

标签: ember.js

我正在尝试拆分控制器的模型数组,以便更容易显示,但我提出的方法是不对的。如何访问控制器的模型数组,以便可以对其进行操作并仍然维护模型的计算属性?

控制器:

export default Ember.Controller.extend({

  queryParams: ['page'],
  page: "",

  playlists: Ember.computed("model", function(){
    var playlistContent = this.get("model.content");
    return _.chunk(playlistContent, 3);
  }),

  actions: {
    setPage(page){
    this.set("page", page);
  }
});

模板:

{{#each playlists as |playlistGroup|}}
  <div class="row">
    {{#each playlistGroup as |playlist|}}
        <div class="col-md-4">
            <div class="card playlist-card">
                <img class="card-img-top" src={{playlist._data.thumbnail}} alt="Card image cap">
                <div class="card-block">
                    <h4 class="card-title">{{playlist._data.title}}</h4>
                    <p class="card-text">{{playlist._data.description}}</p>
                </div>
            </div>
        </div>
    {{/each}}
  </div>
{{/each}}

1 个答案:

答案 0 :(得分:1)

在路线中,

setupController(controller,model){
  this._super(...arguments);
   controller.set('playlists',_.chunk(model, 3)); 
}