HarmonyOS ArkUI的自定义装饰器能否实现java那种运行时注解的功能

想实现一个简单的功能,根据下发的方法名称,自动去调用特定的类中,被自定义装饰器装饰的方法。

HarmonyOS
2025-01-09 16:16:24
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

可以根据传入的字符串动态去掉用对应的方法:

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

  build() {
    Column() {
      Text(this.message)
        .id('DynamicFuntionDemoHelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
      Button('动态调用函数')
        .onClick(() => {
          let demo = new dddd()
          demo.fun['ssss']()
          demo.fun['sdss']()
        })
    }
    .height('100%')
    .width('100%')
  }
}

export class dddd {
  fun: Record<string, Function> = {};

  constructor() {
    this.fun = { 'ssss': this.ddd1, 'sdss': this.ccc }
  }

  ddd1() {
    console.log('ddd1')
  }

  ccc() {
    console.log('cccc')
  }
}
分享
微博
QQ
微信
回复
2025-01-09 18:54:02
相关问题
HarmonyOS 能否自定义自己装饰
412浏览 • 1回复 待解决
HarmonyOS ArkTS 如何实现自定义装饰
370浏览 • 1回复 待解决
HarmonyOS 自定义注解实现方案
360浏览 • 1回复 待解决
自定义装饰使用问题
1100浏览 • 1回复 待解决
HarmonyOS 自定义装饰this指向问题
380浏览 • 1回复 待解决
HarmonyOS 怎么自定义装饰
361浏览 • 1回复 待解决
是否支持自定义装饰
2399浏览 • 1回复 待解决
HarmonyOS 是否支持自定义装饰
587浏览 • 1回复 待解决
HarmonyOS 如何自定义注解
721浏览 • 1回复 待解决
HAP和HAR运行时内存模型
730浏览 • 1回复 待解决
HarmonyOS装饰注解实现方式咨询
818浏览 • 1回复 待解决
ArkTS是否支持自定义装饰
2987浏览 • 1回复 待解决
HarmonyOS 使用AppStartup,运行时异常
463浏览 • 1回复 待解决
获取运行时编译构建参数
1501浏览 • 1回复 待解决
测试脚本运行时安装app报错
754浏览 • 1回复 待解决
ArkTs 有运行时创建指定类方法吗?
770浏览 • 1回复 待解决