是否可以申明一个静态的map并使用?


const tabListData = { 
  "tabListTrade": { 
    "list": [{ 
      "titleId": "A", 
      "pagePath": "url", 
      "text": "A title", 
      "toolBar": "toolBar.toolRefresh" 
    }, { 
      "titleId": "B", 
      "pagePath": "url", 
      "text": "B title", 
      "toolBar": "toolBar.toolRefresh" 
    }, { 
      "titleId": "C", 
      "pagePath": "native", 
      "text": "C title", 
      "params": {"type": "1"}, 
      "toolBar": "toolBar.toolRefresh" 
    }], 
    "model": "0" 
  } 
};  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

是否可以定义一个上面的map,并使用它。

HarmonyOS
2024-11-05 10:13:52
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

​建议使用HashMap,参考链接:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-hashmap-V5#hashmap

参考demo如下:​

class ListData { 
  titleId?: string = "" 
  pagePath?: string = "" 
  text?: string = "" 
  toolBar?: string = "" 
} 
 
class TabListData { 
  list?: ListData[] = [] 
  model?: string = "" 
} 
 
type Type = (string | number | TabListData) 
let map = new HashMap<string, Type>(); 
map.set("tabListTrade", {"list":[{"titleId":"","pagePath":"","text":"","toolBar":""}],"model":"0" }) 
 
Logger.info(map.get("tabListTrade"))
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
分享
微博
QQ
微信
回复
2024-11-05 17:51:59
相关问题
如何申明一个代理使用
729浏览 • 2回复 待解决
HarmonyOS定义一个map为临时变量
1058浏览 • 1回复 待解决
HarmonyOS是否可以申明多个头文件
1194浏览 • 1回复 待解决
TaskPool是否可以访问静态成员
2422浏览 • 1回复 待解决
如何调用测试一个wifi接口?
7306浏览 • 1回复 待解决
如何快速将一个Map对象转为Json字符串
1546浏览 • 1回复 待解决
如何生成一个可以交互移动子窗口
1657浏览 • 1回复 待解决