- 点击按键updata云数据库,第一条记录更新成功,再次按键,或再次运行程序点击按键,更新不成功?
const db= wx.cloud.database() Page({ onchick:function(){ var mt=19 db.collection("time").where({ //查询time云数据库 htime: mt }) .get() .then(res=>{ console.log(res); var tim=res.data[0].time; //得到 tim db.collection("timeone").add({ //写入timeone云数据库 data: { htimone:tim, htim2:0, }, success(res) { console.log("添加成功", res) }, fail(res) { console.log("添加失败", res) } }) db.collection("timeone").where({ //查询数据库 htim: (tim) }) .get() .then(res => { console.log(res); var tmid = res.data[0]._id; //查询出id var tim2=tim+1; db.collection("time").where({ //查询 bhtime:(tim2) }) .get() .then(res=>{ console.log(res); var tim3=res.data[0].time; //得到tim3 db.collection("timeone").doc(tmid).update({ //更新云数据库记录 data: { htim2:tim3 }, success: res => { console.log('成功', res.data) } }) }); }) }) } })
2020-05-14 - res返回的数据,在括号外获取不了?
res返回的数据,在括号外获取不了? onload:function(){ const db= wx.cloud.database() db.collection("time").where( xxxx: msms //查询云数据库 ) .get() .then(res=>{ console.log(res); var mmn2=res.data[0].hhtd; //hhtd为数据库中的字段 console.log("test 测试1",bh) this.setData({ mmn2: res.data[0].hhtd }) }) var wmmn2=this.data.mmn2 //获取不了mmn2,但能获取this.data???? console.log("test 测试1",wmmn2) //获取不了 wmmn2 ????? }
2020-05-13 - 1、index.js怎样传递参数到app.js中的函数tm呢?
1、app.js中的函数可以传参数到index.js, index.js怎样传递参数到app.js中的函数tm呢?求 大师指导 一、app.js中的函数传参数到index.js 1、 index.js: app.tm(function (tm) { console.log(tm) }) 2、app.js: tm: function (cb) { var dd = 'yyy' typeof cb == "function" && cb(dd) //返回输出 }, 二、index.js怎样传递参数到app.js中的函数data???????????? 1、 index.js: onload:function(){ this.setData({ mm:20 }) } 2、app.js: data: function () { console.log(this.data.mm) },
2020-05-13