ember.js displaying list of items, each item with it's own view/controller

前端 未结 2 2036
再見小時候
再見小時候 2021-02-10 16:59

What I want to achieve: create controller with view, and in this view I have list of \'Gallery\' objects. Each item has it\'s own view and controller.

All files are her

2条回答
  •  被撕碎了的回忆
    2021-02-10 17:17

    I suggest you to use an Ember.CollectionView.

    Your galleriesIndex template will looks like:

    {{view App.GalleriesListView contentBinding="this"}}

    The view:

    App.GalleriesListView = Ember.CollectionView.extend({
        classNameBindings: [':thumbnail', ':thumbnails-list'],
        itemViewClass: Ember.View.extend({
            templateName: "galleriesListItem",
            hover: false,
            mouseEnter: function() { this.set('hover', true); },
            mouseLeave: function() { this.set('hover', false; }
        })
    });
    

    The galleriesListItem template:

  • {{view.content.name}}

    {{#if view.hover}} {{/if}}
  • I am not sure there is no error in my code, I just copy-paste and write how it should looks like.

    Concerning the TODO you saw, this is because the Ember.CollectionView actually needs all the ember-handlebars module instead of just the file it needs, you should not care about that.

提交回复
热议问题