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%')
  }
}

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

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