collection.where.get 里设置setData后,数据未更改
今天遇到一个查询数据库以后setData不成功的问题。查询完赋值,退出 get({}) 以后再查询数据值又回去了。 但是有一点比较奇怪,console.log() 显示的数据里“汇总信息”与“展开信息”不一致。 [图片] [图片]代码片段如下: data: {
exRec: true,
focused: false,
searched: false,
inputValue: '',
list: [],
},
.....
recording: function(e) {
var idx = e.currentTarget.dataset.index;
var l = this.data.list[idx]
//记录当前日期
var mDate = new Date()
var M = mDate.getMonth()
var D = mDate.getDate()
if (M < 10) {
M = "0" + M
}
if (D < 10) {
D = "0" + D
}
//查询今日是否已有记录
db.collection('resiRecord').where({
_date: M + "/" + D,
_name: l._name,
_addr: l._addr,
_t1: ''
}).get({
success: res => {
if (res.data.length == 0) {
this.setData({
exRec: false,
})
console.log(this.data)
}
}
})
console.log(this.data)
if (this.data.exRec == false) {
console.log("执行")
db.collection("resiRecord").add({
data: {
_date: M + "/" + D,
_t0: mDate.getHours() + ':' + mDate.getMinutes(),
_name: l._name,
_tel: l._tel,
_addr: l._addr,
_car: l._car,
_qrt: l._qrt,
_quarYN: l._quarYN
}
})
complete: () => {
console.log("finished")
// wx.navigateTo({
// url: '../complement/complement?name=' + l._name + '&tel=' + l._tel + '&addr=' + l._addr + '&car=' + l._car + '&qrtYN=' + l._quarYN + '&qrt=' + l._qrt + '&id=' + l._id
//})
}
} else {
// wx.navigateTo({
// url: '../returner/returner?name=' + l._name + '&tel=' + l._tel + '&addr=' + l._addr + '&car=' + l._car + '&qrtYN=' + l._quarYN + '&qrt=' + l._qrt + '&id=' + l._id
// })
}
},