HarmonyOS 列表复用问题?

在列表List1的底部的ListItem中再添加一个List2,当滑动List1时,发现当List2滚到顶部时,List1的ListItem会触发aboutToReuse的方法,触发的个数跟cacheCount的个数一样。

请问为什么会在aboutToRecycle之后,马上出现cacheCount个数ListItem的aboutToReuse。

参考代码如下

List() {
  LazyForEach(this.controller.data, (item: BaseTemplate, index: number) => {
    ListItem() {
      item.getWrappedBuilder().builder(item)
    }
  },(item: BaseTemplate, index: number)=>{
    return item.model.key
  })

  ListItem() {
    List() {
      LazyForEach(this.controller.data2, (item: BaseTemplate, index: number) => {
        ListItem() {
          item.getWrappedBuilder().builder(item)
        }
      }, (item: BaseTemplate, index: number) => {
        return item.model.key
      })
    }.height('100%').width('100%').backgroundColor(Color.Brown)
  }
}.height('100%').width('100%').backgroundColor(Color.Gray).cachedCount(5)
阅读 510
1 个回答

滑过多少个就预加载多少个,保持预加载屏外上下各cachount个item

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进