微信小程序 setData 数组 渲染问题 删除之后的数组渲染不正确

时间:2019-07-11 20:17:58   收藏:0   阅读:336
list: [
      { id: 0, mode: 1, src: ‘https://s2.yzlcq.cn/images/10070.png‘, text: ‘0‘ },
      { id: 1, mode: 1, src: ‘https://s2.yzlcq.cn/images/10070.png‘, text: ‘1‘ },
      { id: 2, mode: 1, src: ‘https://s2.yzlcq.cn/images/10070.png‘, text: ‘2‘ }
    ],
onDelete(e) {
    var no = Number(e.currentTarget.dataset.index);
    console.log(no)
    var that = this
    wx.showModal({
      title: ‘提示‘,
      content: ‘您确认删除该图片和描述信息吗?确定将删除图片和描述信息‘,
      success(res) {
        if (res.confirm) {
          var ls = that.data.list;
          ls.splice(no, 1)
          console.log(ls)
          that.setData({ list: [] }) //先置空,不然渲染界面不正确 ,一定要注意
          that.setData({ list: ls })
        }
      }
    })
  }

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!