scroll-view 追加数据会自动回到顶部,请问怎样解决?
发布于 7 年前 作者 yangyi 10360 次浏览 来自 官方Issues

没有把数组值全部替换,是不断将数据追加push进数组。

基础库版本:2.10.3

const updateList = `tabs[${activeTab}].list[${page}]`
const updatePage = `tabs[${activeTab}].page`
this.setData({
    [updateList]: res,
    [updatePage]: page + 1
})
<!-- 这是自定义组件的内部WXML结构 -->
<scroll-view class="tab-content" enable-back-to-top="{{true}}" scroll-y="{{true}}" scroll-anchoring="{{true}}" lower-threshold="100" bindscrolltolower="updateGameList">
    <view class="game-card-wrap" wx:for="{{gameListWrap}}" wx:for-item="gameList" wx:for-index="gameListIdx" wx:key="gameListIdx">
        <view class="game-card" hover-class="hover-class" hover-start-time="100" wx:for="{{gameList}}" wx:for-item="game" wx:for-index="gameIdx" wx:key="gid">

        </view>
    </view>
</scroll-view>
3 回复

渲染数组时,我也是采用二维数组,每次setData都只更新本次请求得到的数据。比每次都更新整个数组要高效,所以二维数组是可取的。

没遇到过 我也是 push写的,没有返回顶部。

给你写了个代码片段:

https://developers.weixin.qq.com/s/cqXWHVmL7RfJ

回到顶部