Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone collection fetch (add:true) does not update the collection

loadMore: function(){
    var $this = this;
    console.log(this.Messages); //SAME AS AFTER
    this.Messages.url = '/js/messages/?start=' + this.Messages.length
    this.Messages.fetch({'add':true,
        success:function(){
            console.log($this.Messages); //SAME AS BEFORE??
        },
        error:function(){
        }
    });
 },

The collection is not updated. After this function, the events are fired, and the new items are drawn on the screen. The problem is that the collection did not add the new models.

like image 376
TIMEX Avatar asked Mar 09 '13 03:03

TIMEX


1 Answers

As was mentioned in a previous answer the add option was removed in 1.0.0. You can accomplish the same thing by passing remove: false instead. From the docs:

The behavior of fetch can be customized by using the available set options. For example, to fetch a collection, getting an "add" event for every new model, and a "change" event for every changed existing model, without removing anything: collection.fetch({remove: false})

like image 188
Radu Avatar answered Nov 02 '22 18:11

Radu