data: {
cnt : 0,
TodoResult:[],
},
let self = this;
const db = wx.cloud.database({env: 'lsun-grid-afyq8'})
db.collection('Building').where({
Neighbourhood: _Neighbourhood
}).count().then(res => {
this.setData({cnt : res.total}),
console.log("11111", res.total)//这行能打印出21
})
console.log("count:",self.data.cnt)//这行只能打印出0
……
这样写为什么打印出来的count是0?实际应为21
异步赋值啊,并不是BUG,学学js