【发布时间】:2022-08-07 15:49:24
【问题描述】:
我有这样的数据
var sendlocal = [
{
\"firstName\": \"tree\",
\"lastName\": \"tree\",
\"relativeEmail\": \"tree@gmail.com\",
\"relativeType\": 0,
\"subid\": 1,
\"subRelatives\": [
{
\"firstName\": \"julia2\",
\"lastName\": \"Michle\",
\"relativeEmail\": \"test@hotmail.com3\",
\"relativeType\": 2,
\"subid\": 2,
\"subRelatives\": [
{
\"firstName\": \"john\",
\"lastName\": \"bravo\",
\"relativeEmail\": \"johny@gmail.com\",
\"relativeType\": 1,
\"subRelatives\": [],
\"subid\": 3,
},
{
\"firstName\": \"simith\",
\"lastName\": \"bravo\",
\"relativeEmail\": \"johny@gmail.com\",
\"relativeType\": 1,
\"subRelatives\": [],
\"subid\": 4,
},
],
},
{
\"firstName\": \"julia3\",
\"lastName\": \"Michle\",
\"relativeEmail\": \"test3@hotmail.com\",
\"relativeType\": 2,
\"subRelatives\": [],
\"subid\": 5,
},
],
},
];
根据下面的答案(谢谢)我创建了一个这样的函数
getIndexFromNestedList(List mapValue) { 如果(地图值!= null){ for(mapValue 中的 var 关系){ 打印(关系[\'subid\']); 打印(关系[\'相对电子邮件\']);
if (relation[\'subRelatives\'] != null) {
for (var subRelation in relation[\'subRelatives\']) {
print({relation[\'subid\'], subRelation[\'subid\']});
// graph.addEdge(relation[\'subid\'], subRelation[\'subid\']); //like this
Future.delayed(Duration(milliseconds: 1), () {
getIndexFromNestedList(relation[\'subRelatives\']);
});
}
}
}
}
}
并像这样传递数据
var check = getIndexFromNestedList(relatives);
我得到这样的回应
flutter: {1, 2}
flutter: {1, 3}
4flutter: {2, null}
期望的是 {2,3} {2,4} 也是,但它显示为 null 不知道为什么它会去亲戚。