【问题标题】:Dart/Flutter - How to delete key-value-pairs of element of Map inside a List?Dart/Flutter - 如何删除 List 中 Map 元素的键值对?
【发布时间】:2021-02-25 13:55:25
【问题描述】:

我怎样才能为每个地图删除该类型的 List> 中的特定键值对。

例如:

List> 操作之前:

List<Map<String, dynamic>> currencies = [
    {
      'id': 1,
      'name': 'coin',
      'desc': 'This is just a blindtext.',
      'order': 101,
      'icon': 'https://icon1.jpg'
    },
    {
      'id': 2,
      'name': 'karma',
      'desc': 'This is just a blindtext.',
      'order': 102,
      'icon': 'https://icon2.jpg'
    },
    {
      'id': 3,
      'name': 'laurel',
      'desc': 'This is just a blindtext.',
      'order': 104,
      'icon': 'https://icon3.jpg'
    },
  ];

List> 我正在搜索的操作之后:

List<Map<String, dynamic>> currencies = [
    {
      'id': 1,
      'name': 'coin',
      'icon': 'https://icon1.jpg'
    },
    {
      'id': 2,
      'name': 'karma',
      'icon': 'https://icon2.jpg'
    },
    {
      'id': 3,
      'name': 'laurel',
      'icon': 'https://icon3.jpg'
    },
  ];

所以基本上,我删除了“不需要的”键值对。 有什么建议吗?

提前致谢!!

【问题讨论】:

    标签: list flutter dictionary dart


    【解决方案1】:
    currencies.forEach((item) => item..remove("order")..remove("desc"));
    

    【讨论】:

    • 非常感谢!我尝试了类似的方法,但没有达到我想要的效果!
    猜你喜欢
    • 1970-01-01
    • 2020-08-13
    • 2020-03-14
    • 2020-10-04
    • 2020-12-18
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多