Magical events do not fire after updating events through a selection

I use backbone.marionette and have the following CollectionView ItemView combination:

  PlansListItemView = PlansApp.ItemView.extend
    tagName: "tbody"
    template: "#plansRow"    
    events:
      'click th.expander': 'expandDocuments'

    expandDocuments: (e) =>
      # do stuff

  PlansCollectionView = PlansApp.CollectionView.extend
    tagName: "table"
    itemView: PlansListItemView 

I am creating a view from the original json collection embedded in the page. Event hash events work great.

Then, in the drop-down list change event, I call fetch () on the collection to get a new collection of objects. DOM will be restored, but event handlers will not be reconnected /

Does anyone have any idea why this might happen?

+3
source share
1 answer

Although I don’t know the exact reason for the hands, there are some funny things in your setup that make me think this might be part of the problem.

. , , . , , . , , , , , , .

HTML?

<tbody>, , <th>, , , .

HTML, :

<table>
  <tbody>
    <th></th>
  </tbody>
</table>

, #plansRow, , - .

, . , , , , , . , .

, CompositeView, CollectionView, .

Marionette CompositeView tr. :


RowView = Backbone.Marionette.ItemView.extend({
  template: "#row-template",
  tagName: "tr"
});

TableView = Backbone.Marionette.CompositeView.extend({
  template: "#table-template",
  tagName: "table",

  appendHtml: function(cv, iv){
    cv.$("tbody").append(iv.el);
  }
});

a <table> . <thead><th>...</th></thead><tbody></tbody> .

<tr> , <td>.

appendHtml <tbody> .

JSFiddle: http://jsfiddle.net/derickbailey/me4NK/

, CompositeView, : http://lostechies.com/derickbailey/2012/04/05/composite-views-tree-structures-tables-and-more/

+1

All Articles