lorless
lorless

Reputation: 4478

Backbone sync not updating collection

I thought this would update my model with the response from the server (the call works fine and returns the expected values) but my collection and its models are not being updated. What's wrong with this? Its using create because it posts the the collection which is then returned with changes. As I mentioned the changes come back but the console.log shows that the collection has not changed.

test: function(){
        Backbone.sync('create', this.importCollection, {
        success : _.bind(function(e) {
            console.log(this.importCollection);
            },this)
        });
    },

Upvotes: 0

Views: 147

Answers (1)

gbsice
gbsice

Reputation: 541

If you look at Backbone.Sync method in the annotated source, you can see that nowhere does it ever manipulate the model/collection directly, it only makes the ajax call using the model/collection instance.

If you want to call the Backbone.Sync method manually, you're gonna have to populate your collection manually after the ajax call is done. If you want to see how Backbone does it, you can take a look at the Backbone.Collection fetch method.

Upvotes: 1

Related Questions