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

10,794

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})

Share:
10,794
TIMEX
Author by

TIMEX

Updated on July 29, 2022

Comments

  • TIMEX
    TIMEX almost 2 years
    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.