在aboutToAppear中使用for循环动态初始化SelectDialog的radioContent。
import { SelectDialog } from '@kit.ArkUI'; @Entry @Component struct SelectDialogDemo { // title数组 titleList: string[] = []; // SelectDialog的radioContent进行初始化 radioContent: Array<SheetInfo> = []; // 设置默认选中radio的index radioIndex = 0; dialogControllerList: CustomDialogController = new CustomDialogController({ builder: SelectDialog({ title: '文本标题', selectedIndex: this.radioIndex, confirm: { value: '取消', action: () => { }, }, // 将初始化后的radioContent赋值给SelectDialog的radioContent属性 radioContent: this.radioContent }), }); build() { Row() { Stack() { Column() { Button('纯列表弹出框') .width(96) .height(40) .onClick(() => { this.titleList.push('文本'); this.titleList.push('文本文本'); this.titleList.push('文本文本文本'); this.titleList.push('文本文本文本文本'); this.titleList.push('文本文本文本文本文本'); this.titleList.push('文本文本文本文本文本文本'); // 赋值给radioContent this.titleList.forEach((value: string, index: number) => { let sheetInfo: SheetInfo = { title: value, action: () => { this.radioIndex = index; } }; this.radioContent.push(sheetInfo); }); this.dialogControllerList.open(); }); }.margin({ bottom: 300 }); } .align(Alignment.Bottom) .width('100%') .height('100%'); } .backgroundImageSize({ width: '100%', height: '100%' }) .height('100%'); } }