HarmonyOS 根据列表的title,刷新列表的数据

HarmonyOS
2024-12-18 14:53:15
760浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以参考以下demo实现:

@Entry
@Component
struct Index {
  @State focusIndex: number = 0;
  private controller: TabsController = new TabsController();
  tabArray = [0, 1,2,3,4,5,6,7];

  // 自定义页签
  @Builder
  Tab(tabName: string, tabItem: number, tabIndex: number) {
    Column({ space: 20 }) {
      Text(tabName).fontSize(18)
      Image($r('app.media.icon')).width(20).height(20)
    }
    .width(100)
    .height(60)
    .borderRadius({ topLeft: 10, topRight: 10 })
    .onClick(() => {
      this.controller.changeIndex(tabIndex);
      this.focusIndex = tabIndex;
    })
    .backgroundColor(tabIndex === this.focusIndex ? '#ffffffff' : '#ffb7b7b7')
  }

  build() {
    Column() {
      Column() {
        // 页签
        Row({ space: 6 }) {
          Scroll() {
            Row() {
              ForEach(this.tabArray, (item: number, index: number) => {
                this.Tab('页' + item, item, index);
              })
            }.margin({right: 80})
            .justifyContent(FlexAlign.Start)
          }
          // 设置左对齐
          .align(Alignment.Start)
          .scrollable(ScrollDirection.Horizontal)
          .scrollBar(BarState.Off)
          .width('80%')
          .backgroundColor('#ffb7b7b7')
        }
        .width('100%')
        .backgroundColor('#ffb7b7b7')

        // tabs
        Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
          ForEach(this.tabArray, (item: number, index: number) => {
            TabContent() {
              Text(' 我是页面 ' + item + ' 的内容')
                .height(300)
                .width('100%')
                .fontSize(30)
            }
            .backgroundColor(Color.Pink)
          })
        }
        .barHeight(0)
        .animationDuration(100)
        .onChange((index: number) => {
          console.log('foo change');
          this.focusIndex = index;
        })
      }
      .alignItems(HorizontalAlign.Start)
      .width('100%')
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
分享
微博
QQ
微信
回复
2024-12-18 16:31:22


相关问题
HarmonyOS 列表刷新时候会闪
947浏览 • 1回复 待解决
列表数据更新后页面不刷新
344浏览 • 1回复 待解决
HarmonyOS 列表刷新问题
1319浏览 • 1回复 待解决
HarmonyOS 通知列表刷新事件
710浏览 • 1回复 待解决
HarmonyOS ForEach列表刷新问题
909浏览 • 1回复 待解决
HarmonyOS 列表多选页面无法刷新
667浏览 • 1回复 待解决
刷新列表加载更多问题
1026浏览 • 1回复 待解决
数组列表如何实现数据双向同步?
1207浏览 • 1回复 待解决
分组列表实践(嵌套列表
1926浏览 • 1回复 待解决
HarmonyOS 懒加载列表更改属性UI不刷新
742浏览 • 1回复 待解决