快应用问题:怎么将回调函数中的返回值赋给外部变量?
问题描述:
我是这样写的,但是赋值不上,仍然为空,请教一下
onReady() {
let len = this.markers.length + 1
this.watchHeight = len > 3 ? '450' : len*150+''
const that = this
prompt.showToast({
message: '请稍后,加载中...'
})
device.getUserId({
success (res){
that.userId = res.userId
},
fail (data, code) {
prompt.showToast({
message: '出错了!错误码为:'+code
})
}
})
prompt.showDialog({
message: that.userId
})
}
答
device.getUserId({
success: function(res){
that.userId = res.userId
}.bind(this),
fail (data, code) {
prompt.showToast({
message: '出错了!错误码为:'+code
})
}
})