微信小程序wx.showModal中this.setData不能赋值问题
如果函数间有嵌套的话this.setData中的this是代表最近的函数, var that =this 要在最外层的函数中
// A code block
a:function(){
var that =this
wx.showModal({
title:'删除历史记录',
content:'是否删除全部历史记录',
success:function(res){
if(res.confirm){
console.log('用户点击了确定')
that.setData({
wxHistoryItem:null
})
}else {
console.log('用户点击了取消')
}
}
})
}
关键语句var that =this,否则直接使用 this.setData会报错