jeudi 25 juin 2015

CollectionComponent for Ember 1.13

Since you are discouraged in Ember 1.13 to use Views and instead migrate to Components I'd like to migrate the CollectionView to a component that I can reuse. The version I have below doesn't work because {{view}} is not a string. And it's probably better to use Glimmer directly. But I'm not sure how to render the subviews.

App.CollectionComponent = Ember.Component.extend
  content: []
  itemComponentClass: Ember.Component
  createChildView: (componentClass, data) ->
    new componentClass data
  childComponents: Ember.computed 'content',
    get: ->
      @get('content').map (model) ->
        @createChildView.call this, @itemComponentClass, content: model
  layout: Ember.HTMLBars.compile('{{#each childComponents as |view|}}{{{view}}}{{/each}}')

App.TestListComponent = QLVision.CollectionComponent.extend
  tagName: 'ul'
  content: [1, 2, 3]
  itemComponentClass: Ember.Component.extend
    tagName: 'li'
    layout: Ember.HTMLBars.compile('Content: {{content}}')




Aucun commentaire:

Enregistrer un commentaire