Get REST Ember-Data response value

Amber: 1.0.0-rc.6

Ember-Data: e999edb (2013-07-06 06:03:59 -0700)

I am making a REST (POST) call to login the user. Server response approved. I need an identifier from the server, but I only got the ID with "setTimeout".

I think this is the wrong way.

What's my mistake?

Inside the controller, I call:

var login = App.Login.createRecord(this.getProperties("email", "password"));

login.on("didCreate", function(record) {
  console.log(record.get("id"));     // ID is null
  console.log(record.get("email"));
});

setTimeout(function() {
  console.log(login.get("id"));     // ID is available
  console.log(login.get("email"));
}, 500);

DS.defaultStore.commit();
+1
source share
1 answer

You are right - there is an error in ember-data, where an event materializeDatathat basically sets id and expands the server response does not occur until AFTER the callback didCreate. So what happens in your callback login.on("didCreate" ....), the record is still not implemented.

, - . : https://github.com/emberjs/data/issues/405#issuecomment-17107045

, (?) - Ember.run.next:

login.on("didCreate", function(record) {
  Ember.run.next(function() {
    console.log(record.get("id"));     // ID should be set
    console.log(record.get("email"));
  }
});

, , .

, , , . Ember

: https://github.com/emberjs/data/issues/405#issuecomment-18726035

+1

All Articles