HarmonyOS 弹出对话框

import promptAction from '@ohos.promptAction'
let customDialogId: number = 0
@Builder
function customDialogBuilder() {
  Column() {
    Text('Custom dialog Message').fontSize(10)
    Row() {
      Button("确认").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
      Blank().width(50)
      Button("取消").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
    }
  }.height(200).padding(5)
}

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            promptAction.openCustomDialog({
              builder: customDialogBuilder.bind(this)//1,此this是什么类型,在非页面中怎么获得指向页面的this
            }).then((dialogId: number) => {
              customDialogId = dialogId
            })
          })
      }
      .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.

想要在工具类中弹出对话框,开发文档上有以上代码,在页面中运行以上代码,在api12中提示“"Function.bind" is not supported (arkts-no-func-bind)”,但是实际是可以执行,我想请教下为什么,除此之外我想在工具类中使用上述方式弹出对话框,注释1处的this具体是什么类型,如果是页面,那么怎么在工具类中方便的取得指向页面的this

HarmonyOS
2024-12-25 11:15:37
1007浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

在ArkTS中,this的语义仅限于传统的OOP风格,函数体中是禁止使用this的。该this指的是这个页面本身。此处可通过手工包装,多使用一层调用的方式解决。

分享
微博
QQ
微信
回复
2024-12-25 14:24:27
相关问题
HarmonyOS 对话框弹出页面被遮挡
992浏览 • 1回复 待解决
HarmonyOS 对话框布局
596浏览 • 1回复 待解决
HarmonyOS class中创建对话框不能显示
807浏览 • 1回复 待解决
HarmonyOS 页面跳转后对话框不消失
899浏览 • 1回复 待解决
HarmonyOS 自定义对话框的控制器
591浏览 • 1回复 待解决
如何封装一个自定义Dialog对话框
3058浏览 • 1回复 待解决