onLoad: async function (options) { var that = this that.setData({ has_right:parseFloat(options.has_right), sum: options.sum, }) that.setData({ openid: await app.getOpenid() }) console.log(this.data.openid) var that = this var openid = this.data.openid const db = wx.cloud.database() db.collection('information').where({ _openid: openid }).get({ success: res => { console.log(res.data) this.setData({ ne: res.data }) this.setData({ finished: true }) } }) var that=this console.log(that.data.score) },
submit: function (e) { this.setData({ modalHidden: !this.data.modalHidden }) var that = this var openid = this.data.openid var score =this.data.score var has_right=this.data.has_right console.log(that.data.score) var has_right=Math.max(has_right,score) const db = wx.cloud.database() db.collection('information').where({ _openid: openid }). get({ success: res => { console.log(res.data) this.setData({ ne: res.data, }) db.collection('information').doc(openid).get({ success: res => { console.log(res.data) this.setData({ ne: res.data, flag: res.data.prize_flag }) db.collection('information').doc(openid).update({ data:{ score:has_right, }, complete:res=>{ that.setData({ finished:true }) } }) } }) } }) },
是 _.max()
_.max()
代码是怎么写的呢
const db = wx.cloud.database({});
var app = getApp();
const cont = db.collection('information');
Page({
data: {
has_right:null,
resData:null,
sum:null,
openid:null,
flag:null,
score:null,
modalHidden: true
},
onLoad: async function (options) {
var that = this
that.setData({
has_right:parseFloat(options.has_right),
sum: options.sum,
})
that.setData({
openid: await app.getOpenid()
})
console.log(this.data.openid)
var that = this
var openid = this.data.openid
const db = wx.cloud.database()
db.collection('information').where({
_openid: openid
}).get({
success: res => {
console.log(res.data)
this.setData({
ne: res.data
})
this.setData({
finished: true
})
}
})
var that=this
console.log(that.data.score)
},
submit: function (e) {
this.setData({
modalHidden: !this.data.modalHidden
})
var that = this
var openid = this.data.openid
var score =this.data.score
var has_right=this.data.has_right
console.log(that.data.score)
var has_right=Math.max(has_right,score)
const db = wx.cloud.database()
db.collection('information').where({
_openid: openid
}). get({
success: res => {
console.log(res.data)
this.setData({
ne: res.data,
})
db.collection('information').doc(openid).get({
success: res => {
console.log(res.data)
this.setData({
ne: res.data,
flag: res.data.prize_flag
})
db.collection('information').doc(openid).update({
data:{
score:has_right,
},
complete:res=>{
that.setData({
finished:true
})
}
})
}
})
}
})
},
modalBindaconfirm: function () {
this.setData({
modalHidden: !this.data.modalHidden,
})
if (this.data.flag == 1) {
wx.navigateTo
({
url: '../prize/prize',
})
}
else {
wx.reLaunch
({
url: '../rank/rank',
})
}
},
modalBindcancel: function () {
this.setData({
modalHidden: !this.data.modalHidden,
})
wx.reLaunch
({
url: '../rank/rank',
})
},