HarmonyOS 调用数据打印出来都是空的,是什么原因

在使用HashMap过程中:

public static getTipAlertImage(alertStr: string): HashMap<Resource, string> {
   let result: HashMap<Resource, string>= new HashMap<Resource, string>();
   result.set( $r('app.media.defense_billboards') , '远离广告牌');
   result.set( $r('app.media.defense_trees'), '远离树木');
   return result;
}

调用数据打印出来都是空的,是什么原因?

console.log('kiki-----', JSON.stringify(WeatherUtils.getTipAlertImage()))
HarmonyOS
2024-12-27 14:46:07
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

可以参考下面的demo输出数据:

import { HashMap } from '@kit.ArkTS';
@Entry
@Component
struct CallDataEmptyDemo {
  @State message: string = 'Hello World';
  aboutToAppear(): void {
    console.log('开始输出数据---------------')
    console.log('tag-----', demo.getTipAlertImage('key1').get('key1'))
  }
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}
class demo{
  public static getTipAlertImage(alertStr: string): HashMap<string, string> {
    let result: HashMap<string, string>= new HashMap<string, string>();
    result.set( 'key1' , '远离广告牌');
    result.set( 'key2', '远离树木');
    return result;
  }
}
分享
微博
QQ
微信
回复
2024-12-27 16:57:55
相关问题
ForEach无法遍历全部数据是什么原因
2254浏览 • 1回复 待解决
地图定位不准,是什么原因啊?
520浏览 • 1回复 待解决
有谁知道地图无瓦片是什么原因啊?
2301浏览 • 1回复 待解决