【问题标题】:How to add a list in a list to another list如何将列表中的列表添加到另一个列表
【发布时间】:2021-01-21 16:22:08
【问题描述】:

我有一个名为test3 的列表,我想将此列表添加到另一个列表test0。问题是我只想将"noequipment"“子列表”添加到test0

我用下面的代码试了一下:

var test0 = test0 + test3["noequipment"];

这是列表test3

var test3 = [
  {
    "noequipment": [
      {"name": "test0.1", "time": 10},
      {"name": "test0.2", "time": 10},
      {"name": "test0.3", "time": 10},
      {"name": "test0.4", "time": 10},
    ]
  },
  {
    "equipment1": [
      {"name": "test1.1", "time": 10},
      {"name": "test1.2", "time": 10},
      {"name": "test1.3", "time": 10},
      {"name": "test1.4", "time": 10},
    ]
  },
];

【问题讨论】:

  • test0.add(test3["noequipment"]) ?
  • "noequipment 仍然是红色下划线
  • 这是什么错误??

标签: list flutter dart


【解决方案1】:

也许你正在寻找这个答案

for (var i in test3[0]['noequipment']) {
  test0.add(i);
  print("===========>>${test0}");
}

【讨论】:

    【解决方案2】:

    使用下面的代码假设 test0 已经是一个数组

    test0.addAll(test3[0]['noequipment'])
    

    【讨论】:

      【解决方案3】:

      请测试此代码。

       test0.addAll(test3[0]["noequipment"]);
      

      确保父列表定义为var test0 = [] ;

      这里我测试这段代码https://pastebin.pl/view/ff02c9cc

      【讨论】:

      • 感谢您的快速回复,但“noquipment”仍然是红色下划线,即使我已经检查过我是否写对了
      • 请立即查看。 test0.addAll(test3[0]["noequipment"]);
      猜你喜欢
      • 2020-01-23
      • 2018-03-06
      • 2022-06-13
      • 2021-11-21
      • 1970-01-01
      • 2021-08-18
      • 2013-06-08
      • 1970-01-01
      • 2019-09-22
      相关资源
      最近更新 更多