Can I attach a Marionette collection view to existing HTML?

I use a browser using node to display the collection on the server and then using Marionette on the client side.

Is it possible to use Marionette attachView () areas to attach CollectionView to an existing html list?

+4
source share
2 answers

Marionette does not provide a way to do this using the standard API, but it is possible to use some internal CollectionViewMarionette methods . I gave an example here:

http://jsbin.com/zirupeli/1/edit

The key part is the function createChildrenin CollectionView:

var List = Marionette.CollectionView.extend({
  el: 'ul',

  itemView: Item,

  initialize: function() {
    this.createChildren();
  },

  createChildren: function() {
    this.collection.each(function(model) {
      var view = new this.itemView({
        el: 'li:eq(' + (model.get('id') - 1) + ')',
        model: model
      });

      // set up the child view event forwarding
      this.addChildViewEventForwarding(view);

      // Store the child view itself so we can properly
      // remove and/or close it later
      this.children.add(view);
    }, this);
  }
});

ItemView , Marionette CollectionView: this.addChildViewEventForwarding this.children.add. , :

https://github.com/marionettejs/backbone.marionette/blob/master/lib/backbone.marionette.js#L1687

, , , , .

+3

2.0.0 addChildViewEventForwarding .

...

this.addChildViewEventForwarding(view);

...

this.proxyChildEvents(view);

, , @StephenYoung, . .

0

All Articles