Backbone Collection.fetch({update: True}) Doesn't Compare Id Add's Same Model Again
Solution 1:
If there is any change which is not in idAttribute is still thinks the model is new and triggers add
In your code in the fiddle you have also binded "change" event of the collection to "addAll" function
this.collection.bind('change', this.addAll);
If you comment this line, your code will work as you expected.
Here it how it works now: When first fetch function is called "add" event is fired for the item with ip "127.0.0.2" and "change" is fired for the item with ip "127.0.0.1". When fetch function is called for the second time "change" event is fired for both items. For each consecutive call to fetch, "change" event is fired for two items. (side note: refresh event is never trigger at all)
You can write another method to handle the "change" event and in that method you can update existing html element to reflect the update.
Post a Comment for "Backbone Collection.fetch({update: True}) Doesn't Compare Id Add's Same Model Again"