1

I am developing an application in which there are two views.

View 1 is a list of documents, presenting some vital details View 2 is the document it's self. Editable.

The application is multi-user. So the app polls the server for updates to the collection.

The problem is that when collection (view 1) is refreshed (.fetch) it unbinds all events from the child models. Including the one open in view 2. Where as before the fetch, any changes in the document (model) were reflected in the list (collection), after the fetch the document (now old model) is now unrelated to the list (collection).

After looking at the backbone.js source, this is the intended behavior. Is there a work around solution to this?

Justin Alexander
  • 2,004
  • 3
  • 21
  • 25
  • possible solution, is to _.wrap the save method of the model, and on successful save have it re-add it's self to it's parent collection. – Justin Alexander Jun 05 '12 at 10:25

1 Answers1

1

Yes, this is a very common issue. The Collection is reseted and all its references refreshed, even if they target the same Models than before.

I think could be nice idea to implement a Collection.update() method in opposition of Collection.fetch().

Check this tread for approaches to deal with this behavior: Backbone.js collection upsert?

Community
  • 1
  • 1
fguillen
  • 36,125
  • 23
  • 149
  • 210