收藏
回答

如何实现点击删除按钮删除数据库中对应的数据?


// pages/record/record.js

const db = wx.cloud.database()
const pghis = db.collection('pghis')
const _ = db.command
Page({


  /**
   * 页面的初始数据
   */
  data: {


  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoadfunction (options{
    wx.getStorage({
      key"_openid",
      success:res=>{
       this.setData({
        _openid : res.data
       })
      }
    })
    wx.getStorage({
      key"_openid",
      successres => {
        var record;
        pghis.where({
          _openid: res.data
        }).get().then(res => {
          record = res.data[0].data
          this.setData({
            record
          })
          var i = 0;
          for (var key in record) {
            this.setData({
              [`record.${key}.day`]:key
            });
            this.setData({
              [`dataHanding[${i}]`]:this.data.record[key]
            });
            this.setData({
              [`dataHanding[${i}].word`]:decodeURIComponent(this.data.dataHanding[i].word)
            });
            i++
          };
        });
      }
    })
  },
  gobackfunction () {
    wx.redirectTo({
      url'../home/home',
    })
  },
  see:function(event){
    var num = event.currentTarget.id.replace(/see_/,"");
    var a =  decodeURIComponent(this.data.dataHanding[num].url);
    wx.redirectTo({
      url: a+"&later=later"
    })
  },


  del:function(event){
    var _openid =  this.data._openid;
    pghis.where({_openid: _openid}).get().then(res=>{
      console.log(res.data)
    });
  }
})



<van-sticky offset-top="{{ 10 }}">

  <van-tag mark size="largebindtap="goback">返回van-tag>

van-sticky>

<block wx:for="{{dataHanding}}">

  <van-panel title="{{item.day}}status="{{item.grade}}/25" use-footer-slot>

    <view class="text_view">

      <text class="text">{{item.word}}text>

    view>

    <view slot="footerclass="panel_btn">

      <van-button size="smallcolor="#7232dd" round bindtap="seeid="see_{{index}}">查看van-button>

      <van-button size="smalltype="default" round bindtap="delid="del_{{index}}">删除van-button>

    view>

  van-panel>

block>

最后一次编辑于  2020-08-17
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签