You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
2.1 KiB
124 lines
2.1 KiB
// pages/navigation/index/delete/delete.js
|
|
const db=wx.cloud.database();
|
|
|
|
let app=getApp();
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
clothes:[]
|
|
},
|
|
//定义按钮的事件处理函数
|
|
clear(e)
|
|
{
|
|
var clothes=this.data.clothes
|
|
console.log(clothes)
|
|
let index=e.currentTarget.dataset.index
|
|
console.log(index)
|
|
let id=clothes[index]._id
|
|
console.log(id)
|
|
//界面数据删除
|
|
this.data.clothes.splice(e.currentTarget.dataset.index,1);
|
|
this.setData({ clothes: this.data.clothes });
|
|
console.log('删除成功');
|
|
|
|
//初始化云
|
|
wx.cloud.init({
|
|
env:'cloud1-5ggzbo3kcd4ea4e2'
|
|
});
|
|
wx.cloud.callFunction({
|
|
name:'get',
|
|
complete:res=>{
|
|
console.log('云函数获取openid:',res.result.openid);
|
|
wx.setStorageSync('openid',res.result.openid);
|
|
console.log(res);
|
|
}
|
|
}),
|
|
//删除数据库中记录
|
|
db.collection('cloth').where({
|
|
'_id':id
|
|
}).remove({
|
|
success: function(res) {
|
|
console.log(res.data)
|
|
wx.showToast({
|
|
title: '删除成功',
|
|
})
|
|
console.log('数据库删除成功')
|
|
}
|
|
})
|
|
db.collection('cloth').where({
|
|
'_id':id
|
|
}).get({
|
|
success: res =>{
|
|
console.log(res.data);
|
|
}
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
db.collection('cloth').get({
|
|
success: res =>{
|
|
console.log(res.data);
|
|
this.setData({
|
|
clothes:res.data
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
|
|
}) |