backbone.js - Backbone model listener stops working as soon as the model is saved -


in initialize function of backbone view, created following listener:

this.listento(this.model.get('clusters'), 'add remove', this.savechanges); 

this causes savechanges function called first time model added/removed 'clusters' collection. there's 1 line in savechanges function:

this.model.save(); 

once invoked, adding/removing clusters no longer invokes "add" or "remove" event. why saving model destroy listener? can prevented, or there way re-establish listener?

or there fundamental i'm not understanding models and/or collections...?

let's break down code:

you write

this.listento(this.model.get('clusters'), 'add remove', this.savechanges); 

which equal to

var clusters = this.model.get('clusters'); this.listento(clusters, 'add remove', this.savechanges); 

now assume after event set() new clusters object inside model.

the issue here view still listens events same old clusters object, not relevant anymore - model deals object!

another case backbone clears view's event handlers model when it's being removed.. answer sure if you'd share whole code.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -