AbnerMing888 / HarmonyOsRefresh

HarmonyOsRefresh是一个鸿蒙版的刷新组件,超简单使用,支持下拉刷新和上拉加载,支持各种组件,List、Grid、Column、Row……
Apache License 2.0
145 stars 15 forks source link

ListView数据源为空时,itemLayout设置无效 #141

Closed kongweibo-yy closed 1 week ago

kongweibo-yy commented 1 month ago

原本想要在列表无数据时,设置一个当前页面没有数据的提示,但是无数据,itemLayout无效,里面的布局无法显示,请问怎么解决呀 @Builder itemLayout(item:string, index: number) { if (this.data == undefined || (this.data != undefined && this.data.length <= 0)) { Column() { Text(${this.tabsTitle}列表没有查询到相关数据) .fontSize(this.normalSize * this.unFontSize + 'fp') }.width(CommonConstants.FULL_PARENT) .height(CommonConstants.FULL_PARENT) .justifyContent(FlexAlign.Center) } Column() { this.ListItemStyle(item, index) }.padding({ left: 20, right: 20, top: 10, bottom: 5 }) .height(70) .width('100%') }

  ListView({
    items: this.data, //数据源 数组,任意类型
    itemLayout: (item, index) => this.itemLayout(item, index),
    controller: this.refreshController, //控制器,负责关闭下拉和上拉
    isLazyData: false, //禁止懒加载,也就是使用ForEach进行数据加载
    isScrollSpring: false,
    listAttribute: ((attr) => {
      attr.divider.color = $r('app.color.line_color')
      attr.divider.strokeWidth = 1
      attr.divider.startMargin = 20
      attr.divider.endMargin = 20
    }),
    onRefresh: () => {
      //下拉刷新
      this.isRefresh = true
      this.pageNum = 0
      this.getdata()
    },
    onLoadMore: () => {
      //上拉加载
      this.isLoad = true
      this.pageNum = this.pageNum + 1
      console.log('OARefreshLoadList---->加载更多:页码= ' + this.pageNum)
      this.getdata()
    }
  })
xtxiaolu commented 1 month ago

你的调用本身就不对! 设置 你的布局emptyLayout 是否显示错误页面 showEmptyLayout

` @BuilderParam emptyLayout?: () => void; @BuilderParam errorLayout?: () => void; @BuilderParam loadingLayout?: () => void; @Prop showEmptyLayout?: boolean; @Prop showErrorLayout?: boolean; @Prop showLoadingLayout?: boolean;