0

Check out this code, this is my model:

App.Partita = DS.Model.extend({
    data: DS.attr('string'),
    ora: DS.attr('string'),
    evento: DS.attr('string'),
    segno: DS.attr('string'),
    quota: DS.attr('number'),
    vinto: DS.attr('boolean', false),
    giocata: DS.attr('number'),
    vincita: DS.attr('number'),
    cassa: DS.attr('number'),
    remove: DS.attr('boolean', false),

    remover: function () {
        this.deleteRecord();
    this.save();
    }.observes('remove', true),

    vintoChange: function () {
       console.log(this);
       console.log(this.get('isDirty'));
       if(!this.get('isDirty'))
    this.save();
    }.observes('vinto')

});

and I'm using localstorage adapter for the data:

App.LSAdapter = DS.LSAdapter.extend({
namespace: 'app_namespace'
});
App.ApplicationAdapter = DS.LSAdapter;

I don't know why but when the function "vintoChange" is triggered, I always get that the data is dirty even if it was saved before with

.get('model').save();

Can someone explain?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MrColly
  • 63
  • 1
  • 1
  • 5
  • Check the other Q&A, there are a lot of them mentioning isDirty flag. Maybe this one could help [How to manually set an object state to clean (saved) using ember-data](http://stackoverflow.com/questions/13342250/how-to-manually-set-an-object-state-to-clean-saved-using-ember-data?rq=1) – Anto Jurković Nov 20 '13 at 21:53

1 Answers1

0

Are you sure it's saving? You aren't actually validating that it saved. I would bet server side you are happy with the data sent, but client side ember data is throwing an error on the data it got back from the server.

var savePromise = this.save();

savePromise.then(
   function(){ alert('saved'); }, 
   function(){ alert('failed to save'); }
 );
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96