AlphabetIndexer组件没有暴露方法跳转到指定index

AlphabetIndexer组件没有暴露方法跳转到指定index。

HarmonyOS
2024-09-30 10:15:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

1、selected:选中项索引值。

2、onSelect(callback: (index: number) => void):回调中的的index。

可以参考一下:

class CarTable {  
  title: string = ''  
  projects: string[] = []  
}  
  
@Entry  
@Component  
struct AlphabetIndexPage {  
  private value: string[] = ['选', 'A', 'B', 'C', 'D', 'E', 'F', 'G',  
    'H', 'I', 'J', 'K', 'L', 'M', 'N',  
    'O', 'P', 'Q', 'R', 'S', 'T', 'U',  
    'V', 'W', 'X', 'Y', 'Z']  
  @State selectedIndex: number = 0  
  listScroller: ListScroller = new ListScroller()  
  
  private carList: CarTable[] = [  
    {  
      title: 'A',  
      projects: ['xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xxx', 'xxx', 'xxxx', 'xxx', 'xxx']  
    },  
    {  
      title: 'B',  
      projects: ['xx', 'xx', 'xx', 'xx', 'xx', 'xxx', 'xx', 'xxx', 'xxx', 'xx', 'xxx', 'xxx', 'xxxx']  
    },  
    {  
      title: 'C',  
      projects: ['xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xx', 'xxx']  
    },  
    {  
      title: 'D',  
      projects: ['xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xx', 'xx', 'xx']  
    },  
    {  
      title: 'E',  
      projects: ['xxx', 'xxx', 'xx', 'xxx']  
    },  
    {  
      title: 'F',  
      projects: ['xxx', 'xx', 'xxx', 'xxx', 'xx', 'xx', 'xxx', 'xxx']  
    }  
  ]  
  
  @Builder  
  itemHead(text: string) {  
    Text(text)  
      .fontSize(20)  
      .backgroundColor(0xAABBCC)  
      .width("100%")  
      .padding(10)  
  }  
  
  build() {  
    Stack({ alignContent: Alignment.Start }) {  
      Row() {  
        List({ space: 0, initialIndex: 0, scroller: this.listScroller }) {  
          ForEach(this.carList, (item: CarTable) => {  
            ListItemGroup({ header: this.itemHead(item.title) }) {  
              ForEach(item.projects, (project: string) => {  
                ListItem() {  
                  Text(project)  
                    .width("100%")  
                    .height(60)  
                }  
              }, (item: string) => item)  
            }  
          })  
        }  
        .width('70%')  
        .height('100%')  
        .sticky(StickyStyle.Header)  
        .scrollBar(BarState.Off)  
        .edgeEffect(EdgeEffect.None)  
        .onScrollIndex((start: number, end: number) => {  
          this.selectedIndex = end  
        })  
  
        AlphabetIndexer({ arrayValue: this.value, selected: 0 })  
          .selected(this.selectedIndex)  
          .selectedColor(0xFFFFFF)// 选中项文本颜色  
          .selectedBackgroundColor(0xCCCCCC)// 选中项背景颜色  
          .selectedFont({ size: 16, weight: FontWeight.Bolder })// 选中项字体样式  
          .itemSize(28)// 每一项的尺寸大小  
          .onSelect((index: number) => {  
            this.listScroller.scrollToItemInGroup(index - 1, 0, true)  
          })  
      }  
      .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.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
分享
微博
QQ
微信
回复
2024-09-30 16:59:18
相关问题
如何跳转到共享包中的指定页面
3069浏览 • 1回复 待解决
服务卡片如何跳转到指定的页面呢?
6749浏览 • 1回复 待解决
如何跳转到共享包中的指定页面?
1054浏览 • 1回复 待解决
HarmonyOS AlphabetIndexer组件问题
700浏览 • 1回复 待解决
HarmonyOS 跳转到系统设置页面的方法
1277浏览 • 1回复 待解决
HarmonyOS 跳转到设置->通知管理的方法
658浏览 • 1回复 待解决
HarmonyOS Tab指定默认Index
601浏览 • 1回复 待解决