HarmonyOS 用弹出框组件SelectDialog的时候 radioContent怎么赋值动态变量

我用的是SelectDialog弹出框组件,radioContent 想做成动态的,怎么做?

HarmonyOS
2024-12-24 16:55:16
1121浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

请参考以下代码:

import { SelectDialog } from '@ohos.arkui.advanced.Dialog'
@Entry
@Component
struct Index {
  radioIndex = 0;
  radioContent1:Array<SheetInfo> = []
  dialogControllerList: CustomDialogController = new CustomDialogController({
    builder: SelectDialog({
      title: '文本标题',
      selectedIndex: this.radioIndex,
      confirm: {
        value: '取消',
        action: () => {},
      },
      radioContent: this.radioContent1
    }),
    customStyle: true,
    alignment: DialogAlignment.Bottom,
    autoCancel: false
  })
  aboutToAppear(): void {

    let a:SheetInfo = {
      title: '文本1',
      action: () => {
        this.radioIndex = 0
      }
    }
    let b:SheetInfo = {
      title: '文本2',
      action: () => {
        this.radioIndex = 1
      }
    }
    let c:SheetInfo = {
      title: '文本3',
      action:()=>{
        this.radioIndex = 2
      }
    }
    this.radioContent1 = [a,b,c]
  }
  build() {
    Row() {
      Stack() {
        Column() {
          Button("纯列表弹出框")
            .width(96)
            .height(40)
            .onClick(() => {
              this.dialogControllerList.open()
            })
        }.margin({ bottom: 300 })
      }.align(Alignment.Bottom)
      .width('100%').height('100%')
    }
    .backgroundImageSize({ width: '100%', height: '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.
分享
微博
QQ
微信
回复
2024-12-24 19:42:58
相关问题
HarmonyOS constraintSize支持状态变量
973浏览 • 1回复 待解决
HarmonyOS无法在非组件里面弹出
656浏览 • 1回复 待解决
态变量和常规变量有什么区别?
1286浏览 • 2回复 待解决
HarmonyOS 弹出对话
900浏览 • 1回复 待解决