Chaunjie / kai-ui

高颜值组件库,简单易用,同时支持原生和wepy框架
https://chaunjie.github.io/kui/dist
214 stars 33 forks source link

swipeout 删除选中的数据时,自动展开下一个?如图 #19

Closed 531431988 closed 5 years ago

531431988 commented 5 years ago

删除前 image

删除后 image

为何后面的自动展开操作按钮?怎么取消展开操作

Chaunjie commented 5 years ago

@531431988 用的是wepy版本还是原生的版本?

wppeng commented 5 years ago

@531431988 复现了你的问题,正在解决中。先提供个临时解决方案:可以先清空下数据,然后再更新,类似这样:

    this.setData({
      items: []
    }, () => {
      let newArr = [...items]
      newArr.splice(index, 1)
      this.setData({
        items: newArr
      })
    })
wppeng commented 5 years ago

@531431988 另外一个比较好的解决方案: swipeout 组件内加个 reset 方法,先手动加一下,下个版本会更新上去:

   reset () {
      return new Promise((resolve, reject) => {
        this.setData({
          left: 0,
          startX: ''
        }, () => {
          resolve()
        })
      })
    }

然后页面上,先调用组件的 reset 方法,再更新数组:

    const swipeCtx = this.selectComponent('#swipe-' + index)
    swipeCtx.reset().then(res => {
      const newArr = [...items]
      newArr.splice(index, 1)
      this.setData({
        items: newArr
      })
    })
Chaunjie commented 5 years ago

@531431988 该问题是小程序组件bug导致的,你可以使用上述两个方案解决

531431988 commented 5 years ago

好的,感谢

531431988 commented 5 years ago

image

image image 求个demo

Chaunjie commented 5 years ago

@531431988 不要放到onLoad函数内调用该函数,你要在你执行了删除之后在删除数组之前执行该逻辑

Chaunjie commented 5 years ago

@531431988 给你提供一个例子 page-js image page-wxml image 找到kai-ui/swipeout/index.js新增一个方法 image

531431988 commented 5 years ago

我用wepy框架写的,一直取不到ID

Chaunjie commented 5 years ago

@531431988 看看这个能不能解决你的问题链接

531431988 commented 5 years ago

试了无数次,依然取不到 也看是文档说需要usingComponents引入,确实也是这样引入的 this.$wxpage.selectComponent(id or class) 在wepy里面一直都取不到

Chaunjie commented 5 years ago

@531431988 可能你的wepy版本不兼容usingComponents吧,关于这个我没法帮到你,你可以去wepy社区寻求下帮助

531431988 commented 5 years ago

好的,谢谢大佬