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

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

HarmonyOS
2024-12-24 16:55:16
浏览
收藏 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%')
  }
}
分享
微博
QQ
微信
回复
2024-12-24 19:42:58
相关问题
HarmonyOS constraintSize支持状态变量
344浏览 • 1回复 待解决
态变量和常规变量有什么区别?
732浏览 • 2回复 待解决
HarmonyOS无法在非组件里面弹出
244浏览 • 1回复 待解决
HarmonyOS 弹出对话
341浏览 • 1回复 待解决