微信小程序 置顶/取消置顶

wxml

<view wx:for="{{confirmlist}}" wx:for-item="confirm" wx:for-index="index" wx:key="{{ confirm.id }}" class='{{topcid==confirm.id?"top": "untop"}}' >   
  <view data-selindex="{{index}}" bindtap="top"></view>
  ......
</view>

js

Page({
data: {
topflag:'',
confirmlist:[],
},
// 置顶取消置顶
top(e){
var arr = []
var confirmlist = {}
this.setData({
confirmlist: this.data.confirmlistyuan
})
var list = this.data.confirmlist
var selindex = e.currentTarget.dataset.selindex
for (let i in list) {
arr.push(list[i]); //属性
}
var arritem = arr[selindex]
arr.splice(selindex,1);
console.log(selindex)
if(selindex != this.data.topflag){
this.setData({
topflag: selindex
})
arr.splice(0, 0, arritem);
}else{
this.setData({
topflag: ''
})
arr.splice(selindex, 0, arritem);
} for (var i = 0, len = arr.length; i < len; i++) {
confirmlist[i] = arr[i]
}
this.setData({
confirmlist: confirmlist,
}) }, })

wxss

top{
top: 0px;
position: fixed !important;
}
上一篇:QQ好友列表向左滑动出现置顶、删除--第三方开源--SwipeMenuListView


下一篇:剑指Offer23 二叉树中和为sum的路径