HarmonyOS ArkTS有没有点击下拉框触发的事件

select的事件里只有选择选项后触发的事件,现在select的option是需要调用接口动态查询的,有没有办法可以实现

HarmonyOS
2024-12-18 16:00:22
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get
// xxx.ets
@Entry
@Component
struct SelectExample {
  @State text: string = "TTTTT"
  @State index: number = 2
  @State space: number = 8
  @State arrowPosition: ArrowPosition = ArrowPosition.END
  @State options: Array<SelectOption> = [
    { value: 'aaa', icon: $r("app.media.app_icon") },
    { value: 'bbb', icon: $r("app.media.app_icon") },
    { value: 'ccc', icon: $r("app.media.app_icon") },
    { value: 'ddd', icon: $r("app.media.app_icon") }]
  @State options2: Array<SelectOption> = []
  @State selected: string = ''
  @State @Watch('onSelectedIndexUpData') selectedIndex: number = -1

  onSelectedIndexUpData() {
    console.info('数据发生变化')
    if (this.selectedIndex < 0) {
      return
    }
    this.options2.push(this.options[this.selectedIndex])
  }

  build() {
    Row() {
      TextInput({ placeholder: 'input ...', text: this.selected })
        .onChange((value: string) => {
          this.selected = value
          let index = this.options.findIndex(item => item.value === value)
          this.selectedIndex = index >= 0 ? index : -1
          console.info(index.toString())
        })
        .width('60%')
      Select(this.options2)//.selected(this.index)
        .value(this.text)
        .font({ size: 16, weight: 500 })
        .onSelect((index: number, text?: string | undefined) => {
          console.info('Select:' + index)
          this.index = index;
          if (text) {
            this.text = text;
          }
          this.options2.pop()
          this.selectedIndex = -1
        })
    }.width('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-18 18:21:19
相关问题
HarmonyOS XComponent没有点击事件
350浏览 • 1回复 待解决
HarmonyOS ImageSpan点击事件无法触发
812浏览 • 1回复 待解决
HarmonyOS 回车触发点击事件
333浏览 • 1回复 待解决
HarmonyOS onVisibleAreaChange事件没有触发
458浏览 • 1回复 待解决
HarmonyOS 有没有隐私政策弹demo?
454浏览 • 1回复 待解决
HarmonyOS ArkTS 有没有extension
688浏览 • 1回复 待解决
HarmonyOS ArkTS有没有BigDecimal?
510浏览 • 1回复 待解决
HarmonyOS 组件有没有长按事件
352浏览 • 1回复 待解决
鸿蒙中有没有载入控件?
5720浏览 • 1回复 待解决
HarmonyOS ArkTS有没有TS替代方法
402浏览 • 1回复 待解决
HarmonyOS ArkTS有没有内联函数概念
378浏览 • 1回复 待解决
HarmonyOS ArkTS有没有相关资料?
602浏览 • 1回复 待解决