错误代码
for (var i = 0; i < array.length; i++) {
console.log("--------------1" , i)
wx.cloud.database().collection("Word").where({
name: array[i]
}).get()
.then(res => {
console.log("--------------2" , i)
})
当 length 长度为2时 因为微信小程序的是异步处理
控制台输出的是
-------------1 0
-------------1 1
-------------2 2
-------------2 2
for循环都执行完了 才执行查询语句
这个方法 复杂 还行不通
正确代码
var db = wx.cloud.database()
const _ = db.command
wx.cloud.database().collection("Word").where({
name: _.in(array)
}).get()
.then(res => {
})
在where里面使用 _.in(array)