首先我想用movable-view来实现滑动删除的效果,so写法如下:
<movable-area class=“box” wx:for="{{[1,2,3,4]}}" wx:key="{{index}}" style=“width: 120%; margin-left:-20%;” >
<movable-view class=“item” style=“width: 80%; background: #fff;” direction=“horizontal” inertia=“true” out-of-bounds=“true” bindtouchend=‘sEnd’ data-index=’{{index}}’ x="{{setX[index]}}" bindchange=“slider”>
<image class=“userImg” src="/image/user.png" catchtap=“toUserCard” data-index="{{index}}"></image>
<view class=‘item-right’>
<view class=’’>xxxxx</view>
<view class=’’>来源:xxxxx</view>
</view>
<view class=‘status’>等待验证</view>
<!-- <view class=‘applay’>添加</view> -->
</movable-view>
<view class=‘remove’ bindtap=‘remove’>删除</view>
</movable-area>
因为movable-view没有滑动停止触发的事件,所以用到了bindtouchend方法,
slider: function(e){
var index = e.currentTarget.dataset.index
var xlist = this.data.setX
xlist[index] = e.detail.x
},
sEnd: function(e){
var index = e.currentTarget.dataset.index
var xlist = this.data.setX
xlist[index] = xlist[index] >=35 ? 70 : 0
if (index != this.data.preIndex){
if (this.data.preIndex != -1) {
xlist[this.data.preIndex] = 70
}
this.data.preIndex = index
}
this.setData({
setX: xlist,
})
this.data.preIndex = index
}
},
然后问题来了,x设置为0,为什么setData以后,滑动的moveable-view又回到原位置去了(一开始70)
执行完setData以后:
……怎么回事,设置x都不起作用的吗?