dart - HashMap 没有实例键

标签 dart hashmap key

我的代码有什么问题?
widget.woList这个数据类型是 List<HashMap<int, ABC>>()

for (var i in widget.woList) {
  print(i.toString());
}

通过打印上面的代码,我得到
  {5838: ABC(pid: 84201,userId: 545)}

但是,当我只想获取 key ( print(i.key.toString()); )时,出现以下错误:
Class '_HashMap<int, ABC>' has no instance getter 'key'.
Receiver: Instance of '_HashMap<int, ABC>'
Tried calling: key

最佳答案

我认为您还需要遍历 HashMap :

for (HashMap<int, ABC> i in list) {
  i.forEach((key, value) {
    print(key.toString());
    print(value.toString());
  });
}

确保在 for 中使用 HashMap<int, ABC> 输入“i”变量。从您的 IDE 获取自动完成。

关于dart - HashMap 没有实例键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61556690/

相关文章:

ecmascript-6 - Google Dart是否支持ES6代理?

hashmap - 在 struct impl 中访问 hashmap 字段值作为 &mut

java - 按键订购 HashMap?

mysql - 使用未使用的主键

javascript - jQuery 从索引获取关联数组键

Dart 类型测试在局部变量和类成员变量之间的工作方式不同

dart - 在 flutter 中使用自定义脚手架复制 GlobalKey

python - 如何从两个制表符分隔的文件中获取枢轴线?

java - 没有明确答案 : Which Java Map is the cheapest?

flutter - 在 Flutter 中为 ThemeData 添加自定义属性