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

前端 未结 2 1062
深忆病人
深忆病人 2021-02-10 16:44

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:25

    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.

提交回复
热议问题