当前位置 : 主页 > 网络编程 > JavaScript >

删除缓存中的某一项

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.txt //点击删除按钮事件 delItem: function (e) { var that = this; //获取列表中要删除项的下标 var index = e.target.dataset.index; var refactivityid = e.target.dataset.refactivityid; var list = that.data.result; va
gistfile1.txt
//点击删除按钮事件

  delItem: function (e) {
    var that = this;

    //获取列表中要删除项的下标
    var index = e.target.dataset.index;
    var refactivityid = e.target.dataset.refactivityid;
    var list = that.data.result;
    var imgs = that.data.imgs;
    var collectionNum = wx.getStorageSync('collectionNum');

    
    for (let i = collectionNum; i > 0; i--) {

      var coll = 'collection' + i;
      var collection = wx.getStorageSync(coll);
      
      if (collection.refActivityId == refactivityid) {
        wx.setStorageSync(coll, '');
      } 

    }
    
    
    var idlist = wx.getStorageSync('idlist');

    idlist = idlist.replace(refactivityid,'');
    wx.setStorageSync('idlist', idlist)

    list.splice(index, 1);//移除列表中下标为index的项

    imgs.splice(index, 1);//移除列表中下标为index的项

    that.setData({
      result: list,
      imgs,
    });
  },
网友评论