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;
}