Rückgrat.Modell.sparen Sie nicht mein Modell mit der server-Antwort

Ich bin Aufruf von 'speichern unter' auf mein Modell und der Rückkehr das neue Modell als json in meinem PHP-backend. Wenn ich Schritt für Schritt durch das Rückgrat.Modell.save-Methode kann ich sehen, dass es erfolgreich wird der server-Antwort und stellt dann das Modell (in den Optionen.Erfolg Schließung unten). Wenn aber die Ausführung ist wieder auf meiner click-handler, das Modell hat die alten Eigenschaften (dh. die id ist nicht gesetzt). Was könnte passiert sein?

Hier ist mein click-handler:

addButtonClick: function(e) {
  var data = $(e.target).closest('form').serializeObject();
  var p = new Domain.Page; //this extends Backbone.Model
  p.set(data);
  p.save();
  //****
  //**** AFTER p.save, the model p still has the OLD ATTRIBUTES... why??
  //****
  return false;
}

Hier ist Rückgrat der save-Methode:

//Set a hash of model attributes, and sync the model to the server.
//If the server returns an attributes hash that differs, the model's
//state will be `set` again.
save : function(attrs, options) {
  options || (options = {});
  if (attrs && !this.set(attrs, options)) return false;
  var model = this;
  var success = options.success;
  options.success = function(resp, status, xhr) {
    //****
    //**** NEXT LINE SUCCESSFULLY SETS THE MODEL WITH THE SERVER RESPONSE
    //****
    if (!model.set(model.parse(resp, xhr), options)) return false;
    if (success) success(model, resp, xhr);
  };
  options.error = wrapError(options.error, model, options);
  var method = this.isNew() ? 'create' : 'update';
  return (this.sync || Backbone.sync).call(this, method, this, options);
},
InformationsquelleAutor Nick Lang | 2011-10-31
Schreibe einen Kommentar