Mates, i have this code:
var newCustomer = customers.create({
'id_pais' : usrinfo.country,
'nombre' : usrinfo.name,
'apellido' : usrinfo.lastname,
'pasaporte' : usrinfo.passport,
'mail' : usrinfo.mail,
'birth' : usrinfo.birth
});
console.log(newCustomer.get('id'));
// Create Guest
var cama = beds.get(usrinfo.dorm);
var newGuest = guests.create({
'id_room' : cama.get('id_room'),
'id_bed' : usrinfo.dorm,
'id_customer' : newCustomer.get('id'),
'inDate' : usrinfo.inDate,
'outDate' : usrinfo.outDate,
'notas' : usrinfo.notes
});
The thing is, that I need to get newCustomer's RESTFul given id, but don't know any method to wait until the post request is answered from the server. Any ideas?
Thanks!
UPDATE:
I made it work this way:
var newCustomer;
newCustomer = customers.create({
'id_pais' : usrinfo.country,
'nombre' : usrinfo.name,
'apellido' : usrinfo.lastname,
'pasaporte' : usrinfo.passport,
'mail' : usrinfo.mail,
'birth' : usrinfo.birth
}, {
success: function(response){
var a = newCustomer.changedAttributes();
var cama = beds.get(usrinfo.dorm);
var newGuest = guests.create({
'id_room' : cama.get('id_room'),
'id_bed' : usrinfo.dorm,
'id_customer' : a.attributes.id,
'inDate' : usrinfo.inDate,
'outDate' : usrinfo.outDate,
'notas' : usrinfo.notes
});
}
});
So, with:
var a = newCustomer.changedAttributes();
Then I can access to the id, like this:
a.attributes.id
Thanks for the help!
UPDATE 2:
Now the thing is, that backbone's not updating the model's data with the new values returned from the server.
Any idea?
Thanks