【问题标题】:Accessing Map elements in dart在 dart 中访问 Map 元素
【发布时间】:2022-01-16 15:23:17
【问题描述】:

我有一个数据类型的地图

Map<String, Map<String, Key?>> filterOption

它有一些数据

 Map<String, Map<String, Key?>> filterOption={"Certificate Provider":{"nvq":GlobalKey()},"Course Language":{"nvq":GlobalKey()},"Course Amount":{"nvq":GlobalKey()},"Duration":{"nvq":GlobalKey()},"Category":{"nvq":GlobalKey()}};

如何访问每个单独条目的 Key?(全局键值)?

【问题讨论】:

    标签: flutter dart key-value


    【解决方案1】:

    filterOption 上的下标访问运算符[] 与外部映射的键之一结合使用。因为,下标映射返回一个可为空的类型,您可以使用 conditional subscript access operator ?[]'nvq' 从内部映射中获取 GlobalKey

    Key? key = filterOption['Certificate Provider']?['nvq'];
    

    【讨论】:

      猜你喜欢
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多