伙计们,我有这个代码:
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
});
问题是,我需要获取 newCustomer 的 RESTFul 给定 ID,但不知道有什么方法可以等到服务器响应发布请求。有任何想法吗?
谢谢!
更新:
我让它这样工作:
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
});
}
});
所以,有:
var a = newCustomer.changedAttributes();
然后我可以访问 id,如下所示:
a.attributes.id
谢谢您的帮助!
更新 2:
现在的问题是,主干没有使用从服务器返回的新值更新模型的数据。
任何想法?
谢谢