HarmonyOS ArkTS不支持动态声明字段,不支持动态访问字段。只能访问已在类中声明或者继承可见的字段

在JSBridge场景下,需要实现根据callNative动态映射到ArkTs模块方法的逻辑,目前arkTs不支持动态声明字段,除了用switch case或者if else,怎么能够更优雅的实现,比如TS代码如下:

import moduleA from "xxxx" 
import moduleB from "xxxx" 
import moduleC from "xxxx" 
// 数据 
const moduleObj = { 
  moduleName:"moduleA", 
  action:"request", 
  param:{} 
} 
 
const Test = { 
  moduleA: moduleA, 
  moduleB: moduleB, 
  moduleC: moduleC, 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
HarmonyOS
2024-11-22 11:13:11
1061浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

​ArkTS不支持索引访问字段,这边建议 可以使用替代方案,使用Record类型来替代,详情链接:​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-more-cases-V5​​可以使用动态import本地文件方式 使用类、成员函数和方法的字符串名字进行反射调用 简化​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-dynamic-import-0000001829010166

分享
微博
QQ
微信
回复
2024-11-22 15:58:40
相关问题
HarmonyOS 不支持通过索引访问字段
1164浏览 • 1回复 待解决
http不支持cancel方法
906浏览 • 1回复 待解决
arkts不支持bigint数据类型
3076浏览 • 1回复 待解决
HarmonyOS ets不支持匿名吗?
989浏览 • 2回复 待解决
HarmonyOS 不支持查看函数列表
722浏览 • 1回复 待解决
HarmonyOS ArkTS不支持正则匹配吗?
804浏览 • 1回复 待解决
HarmonyOS 编码集不支持
778浏览 • 1回复 待解决
HarmonyOS 推送设备不支持
841浏览 • 1回复 待解决
Toggle isOn不支持$$?
832浏览 • 1回复 待解决
web组件不支持localstorage
1510浏览 • 1回复 待解决
HarmonyOS ArkTS不支持any数据类型做返回
843浏览 • 1回复 待解决
@BuilderParam 不支持普通class变量
1488浏览 • 1回复 待解决
HarmonyOS @State不支持HashMap吗
755浏览 • 1回复 待解决
HarmonyOS image不支持mask吗
844浏览 • 1回复 待解决
HarmonyOS Span不支持n换行
770浏览 • 1回复 待解决
HarmonyOS color文件不支持rgba吗
819浏览 • 1回复 待解决
HarmonyOS RN使用datetimePicker显示不支持
785浏览 • 1回复 待解决
HarmonyOS ArkTD不支持any,如何替换
755浏览 • 1回复 待解决
HarmonyOS TextSpan不支持align
708浏览 • 1回复 待解决
HarmonyOS filePreview 不支持pdf文件预览
1472浏览 • 1回复 待解决