HarmonyOS promptAction.OpenCustumDialog如何绑定数据

我用promptAction.OpenCustumDialog 实现了个dialog ,传入了一个object 数据

我该怎么让dialog里的数据绑定object属性,

或者object 属性改变时主动刷新ui

HarmonyOS
2024-12-24 17:15:54
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

先点击弹窗数据查看一下数据,在关闭弹窗,点击change按钮,改变数据后,在点击弹窗数据查看一下数据,参考示例如下:

import promptAction from '@ohos.promptAction'

let customDialogId: number = 0

class Tmp {
  paramA1: string = ''
  isShow: boolean = false
}

@Builder
function customDialogBuilder($$: Tmp) {
  Column() {
    Text(`overBuilder===${$$.paramA1}`).fontSize(10)
    Text('显示与隐藏').visibility($$.isShow?Visibility.Visible:Visibility.Hidden)
    Row() {
      Button("确认").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
      Blank().width(50)
      Button("取消").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
    }
  }
}

@Entry
@Component
struct Index {
  @State message: string = 'Original'
  @State label: string = 'Custom dialog Message';
  @State isShow: boolean = true;
  @Builder
  customDialogComponent() {
    customDialogBuilder({paramA1: this.label,isShow:this.isShow})
  }

  build() {
    Row() {
      Column() {

        Button('弹窗数据')
          .onClick(() => {
            promptAction.openCustomDialog({
              builder: () => {
                this.customDialogComponent()
              },
              showInSubWindow: false,
              offset: { dx: 5, dy: 5 },
              backgroundColor: 0xd9ffffff,
              cornerRadius: 20,
              width: '80%',
              height: 200,
              borderWidth: 1,
              borderStyle: BorderStyle.Dashed, //使用borderStyle属性,需要和borderWidth属性一起使用
              borderColor: Color.Blue, //使用borderColor属性,需要和borderWidth属性一起使用
              shadow: ({
                radius: 20,
                color: Color.Grey,
                offsetX: 50,
                offsetY: 0
              }),
            }).then((dialogId: number) => {
              customDialogId = dialogId
            })
          })
        Button('change').onClick(() => {
          // After Click me is clicked, the UI text changes from Hello to ArkUI.
          this.label = 'ArkUI';
          this.isShow = false
        })

      }
      .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.

参数传递规则请参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-builder-V5

分享
微博
QQ
微信
回复
2024-12-24 19:28:32
相关问题
HarmonyOS如何实现双向数据绑定
1498浏览 • 1回复 待解决
数据绑定框架使用问题
6975浏览 • 1回复 待解决
ArkTS简单类型变量双向数据绑定
2719浏览 • 1回复 待解决
HarmonyOS 请问TabContent如何与page绑定
1463浏览 • 1回复 待解决
HarmonyOS promptAction.openCustomDialog问题
659浏览 • 1回复 待解决
HarmonyOS PromptAction无法弹出Toast
819浏览 • 1回复 待解决