增删改查
//查
db.collection('publish').where({
type:String(select)
}).get({
success:(res)=>{
const {data}= res
this.setData({
list:data.map(item=>{
return {
...item,
publishTime:formateTime(item.publishTime)
}
})
})
}
})
//删
db.collection('publish').doc(id).remove({
success: () => {
wx.showToast({
title: '删除成功',
icon: 'none',
success: () => {
this.onLoad()
}
})
}
})
//改
db.collection('publish').doc(id).update({
data: {
type,
classify1: multiArray[0][multiIndex[0]],
classify2: multiArray[1][multiIndex[1]],
name,
time,
location,
link,
descript,
imgCloud,
publishTime: new Date().getTime(),
},
success: (res) => {
wx.switchTab({
url: '../index/index',
success: () => {
wx.showToast({
icon: 'none',
title: '修改成功',
})
}
})
}
})
//增
db.collection('collection').add({
data: {
...info,
id: _id //数据库会自动添加唯一的_id,需把之前的_id改成其他并删除
},
success: (res) => {
wx.showToast({
title: '收藏成功',
icon: 'none'
})
collectionIconother.reverse()
this.setData({
collectionIcon: collectionIconother
})
}
})