javascript - Update id after collection.create in Backbone.js -
on collection, using create function save new instance of model server. post request successful , return new model.
{id:135, type:tweet, start:08:00:00, end:14:00:00, text:foo, date:2013-04-01}
however, need update collection new model.id has been returned server , appears sync method in create not this. should add callback create function update model it's changed attributes?
var addscheduleblock = backbone.view.extend({ savescheduleblock: function (ev){ var text = "foo" this.model.set({ text: text }); var block = blockcollection.create(this.model, { silent: true, wait: true }); });
backbone's collection create
method calls model save
method underneath (code reference). don't need set id yourself, backbone you.
the model save
method sets response attributes model (code reference)
if create not doing job, should try debugging it.
Comments
Post a Comment