wx:if条件渲染,第一次加载该页面,能出现弹窗,再从其他页面进去时,在轮询setInterval中,条件满足后,确实把数据变成true了,但是它的弹窗偶尔出现,如果是添加点击事件的话弹窗一定出现
复现很难啊,涉及到数据库什么的,就是我用wx:if做了个弹窗,在一个轮询中查数据库的状态,第一次加载时数据库条件满足时,wx:if变为true,弹窗出现,离开当前页面再进来,轮询还在接着之前的继续,条件再次满足时,设为true但是弹窗不出现,我在前台显示下,显示的是false,给你截下那个轮训的代码
getOrderLength: function () {
var that = this;
var interval2 = that.data.interval2
interval2 = setInterval(function () {
that.setData({
interval2: interval2
})
wx.request({
url: api + ‘/selectNearbyOrder’,
method: ‘POST’,
data: {
driverid: app.globalData.userid
},
header: {
“Content-Type”: “application/x-www-form-urlencoded”
},
success: function (res) {
that.setData({
ordersAllTypeList: res.data.ordersAllTypeList,
// driverOrderListOk: res.data.driverOrderListOk
})
var isNew = false
var obj =app.globalData.obj
var valetObj = app.globalData.objValet
var errObj = app.globalData.objErr
var orderList = res.data.ordersAllTypeList
var index =-1
for(let i=0;i<orderList.length;i++){
var key = orderList[i].orderId
if(orderList[i].type===0){
if(obj.length>0){
for (let j = 0; j < obj.length; j++) {
if(key>obj[obj.length-1]){
isNew=true
obj.push(key)
break
}
}
}else{
isNew=true
obj.push(key)
}
}else if(orderList[i].type===1){
if (valetObj.length > 0) {
for (let j = 0; j < valetObj.length; j++) {
if (key > valetObj[valetObj.length - 1]) {
isNew = true
valetObj.push(key)
break
}
}
} else {
isNew = true
valetObj.push(key)
}
} else if (orderList[i].type===2){
if (errObj.length > 0) {
for (let j = 0; j < errObj.length; j++) {
if (key > errObj[errObj.length - 1]) {
isNew = true
errObj.push(key)
break
}
}
} else {
isNew = true
errObj.push(key)
}
}
if(isNew){
index = i
indexChoose=i
that.setData({
src: app.globalData.musicSrc,
showModalView:true
})
console.log(“state=”+that.data.showModalState)
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = app.globalData.musicSrc
innerAudioContext.onPlay(() => {
})
innerAudioContext.onError((res) => {
console.log(res)
})
// this.audioCtx = wx.createAudioContext(‘myAudio’)
// this.audioCtx.play()
wx.vibrateLong({
success: function (res) {
}
})
var from_address = res.data.ordersAllTypeList[i].from_address
var to_address = res.data.ordersAllTypeList[i].to_address
var longitude = res.data.ordersAllTypeList[i].longitude
var dimension = res.data.ordersAllTypeList[i].dimension
var to_longitude = res.data.ordersAllTypeList[i].to_longitude
var to_dimension = res.data.ordersAllTypeList[i].to_dimension
var type2 = res.data.ordersAllTypeList[i].type
var orderType = res.data.ordersAllTypeList[i].order_type
var orderId = res.data.ordersAllTypeList[i].orderId
var amount = res.data.ordersAllTypeList[i].amount
var carSharingValuation = app.globalData.errandValuation
var taxiValuation = app.globalData.errandValuation
var valetDriverValuation = app.globalData.errandValuation
var errandValuation = app.globalData.errandValuation
that.setData({
type2: type2,
orderType: orderType,
from: from_address,
to: to_address,
price: amount ,
showModalView: true
})
console.log(that.data.showModalView)
var latitudeNow3 = ‘’
var key = config.Config.key;
var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getRegeo({
success: function (data) {
latitudeNow3 = data[0].latitude
var longitudeNow = data[0].longitude
var latitudeNow4 = longitudeNow + ‘,’ + latitudeNow3;
var latitudeNow2 = to_longitude + ‘,’ + to_dimension
// var key = config.Config.key;
// var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getDrivingRoute({
origin: latitudeNow4,
destination: latitudeNow2,
success: function (data) {
var mile = data.paths[0].distance / 1000
that.setData({
mile: mile.toFixed(2),
})
}
})
// orderLength = res.data.ordersAllTypeList.length
}
})
break
}
}
}
})
if (app.globalData.driverState === 0) {
clearInterval(that.data.interval)
clearInterval(that.data.interval2)
}
}, 5000)
},