<view wx:for="{{taskList}}" wx:for-item="item" wx:key="index">
<view class="van-cell-groups {{(colorFlag&&item.fatherFlag==false&&item.pictureAdd==1)?'border-color':''}}" id="a{{item.id}}">
</view>
id不能以数字开头
data: {
toView: '',
scrollTop: 86,
colorFlag:false,
},
//方法
let arr=[]
this.data.taskList.map((item, index) => {
arr.push({id:item.id,key:index})
})
//去重,并排序
var arrcopy2=[...new Set(arr.map(e => JSON.stringify(e)))].map(e => JSON.parse(e))
var arrcopy=[]
arrcopy2.map((a,b)=>{
arrcopy.push(a.id)
})
const query = wx.createSelectorQuery()
query.select('#a' + arrcopy[0]).boundingClientRect()
query.selectViewport().scrollOffset()
query.exec(function (res) {
res[0].top // #the-id节点的上边界坐标
res[1].scrollTop // 显示区域的竖直滚动位置
wx.pageScrollTo({
scrollTop: res[0].top, // 滚动到的位置(距离顶部 px)
duration: 300
});
that.setData({
toView: 'a' + arrcopy[0]
})
})