Javascript get中显示的上一个属性
一个简单的主干存储,导致显示上一个属性的失败获取 我有一个属性captcharesponse,它说明保存时验证码是否正确 当我制作一个控制台模型时,该属性很好地同步并显示在属性中 但是当我制作一个模型时。get(captcharesponse);我总是得到前一个属性 这是我的密码Javascript get中显示的上一个属性,javascript,backbone.js,Javascript,Backbone.js,一个简单的主干存储,导致显示上一个属性的失败获取 我有一个属性captcharesponse,它说明保存时验证码是否正确 当我制作一个控制台模型时,该属性很好地同步并显示在属性中 但是当我制作一个模型时。get(captcharesponse);我总是得到前一个属性 这是我的密码 var set = { 'nom' : v.ui.nom.val() , 'mail' : v.ui.mail.val() , 'suject' : v.ui.suject.val()
var set = {
'nom' : v.ui.nom.val()
, 'mail' : v.ui.mail.val()
, 'suject' : v.ui.suject.val()
, 'telephone': v.ui.telephone.val()
, 'message': v.ui.message.val()
, 'recaptcha_response_field': v.ui.recaptcha_response_field.val()
, 'challenge' : RecaptchaState.challenge
} ;
model.set( set ) ;
model.save( { wait : true }) ;
console.log ( model ) ; // new sync attributes in
var captcharesponse = model.get( "captcharesponse" ) ;
请帮助
保存
是异步的
So model.get(
甚至在从服务器返回响应之前执行。请改用回调
收听同步事件并将您的响应记录在那里
// set variable
// Listen to the model sync event
// this keyword relates to the view if you have any
this.listenTo(model, 'sync', 'getCapcha');
model.set( set ) ;
model.save( { wait : true }) ;
function getCapcha(responseModel) {
console.log ( responseModel) ; // new sync attributes in
var captcharesponse = responseModel.get( "captcharesponse" ) ;
}