user1031947
user1031947

Reputation: 6664

How do I prevent Backbone from updating the model when save is called?

When I call save on a Backbone model...

model.save();

...Backbone expects a JSON response from the server, which it uses to update the model.

How do I prevent Backbone from updating the model when save is called?

Upvotes: 1

Views: 901

Answers (2)

zhongguoa
zhongguoa

Reputation: 336

Maybe you should just use model.set(attributes, [options]) Model-set.

A "change" event will be triggered on the model. No HTTP POST/PUT request

model = new Application({id: 1, title: 'test'})
model.set({attr: 'value', key: 'val'})

model.toJSON()
// => {id: 1, title: "test", attr: "value", key: "val"}

Upvotes: 1

Alexander Lebedev
Alexander Lebedev

Reputation: 6044

One way to do it

model.clone().save()

Original model will remain unchanged.

Upvotes: 4

Related Questions