jeudi 15 septembre 2016

Ember.js - Saving record in Route (Ember Data)

I am having a problem with persisting my record and I can't seem to figure it out... I do not implement a controller, so I'm using the default. I am developing a blueprint to do this, so please excuse the model object here is called bar.

If I break in the debugger before the .save(), I can examine the bar object and see:

bar.get('name')
"xxxxx"
bar.get('hasDirtyAttributes')
true

However, when I continue, the network request has the name property set back to its original value...

Route:

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.modelFor('bar');
  },
  actions: {
    save() {
      let bar= this.controller.get('model');
      bar.save().then(function() {
        console.log("Record saved.");
      }, function(error) {
        console.log("Save error:", error);
      });
    }
  }
});




Aucun commentaire:

Enregistrer un commentaire