1.这种比较奇怪,在定义Data{}时候要加,
如果不加,会导致setData()方法改变不了Data{}里面的值,并且不报错!
代码演示
/**
* 页面的初始数据
*/
data: {
isAdd:false,
},
2.第二种情况比较常规 要用var that=this
因为嵌套里面this 指向的不是js文件中的this,
这里this可能指向callFunction的this
** //正确的代码演示**
queryFavorite:function(id){
var that=this
let openid=""
let article_id = id;
wx.cloud.callFunction({
name: "getopenid",
success(res) {
openid=res.result.openid
DB_favorite.where({
openid:openid,
article_id:article_id
}).get({
success(res){
console.log(res)
if(res.data.length==1){
that.setData({
isAdd:true,
})
}
}
})
}
})
},