1、model
class MultiPickData {
String id;
List<MultiPickData> children;
String name;
MultiPickData(this.id, this.children, this.name);
@override
toString() => 'id: $id';
MultiPickData.fromJson(Map<String, dynamic> json) {
id = json['id']?.toString();
name = json['name']?.toString();
if (json['children'] != null) {
children = [];
children.addAll((json['children'] as List)
.map((m) => MultiPickData.fromJson(m))
.toList());
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
if (this.children != null) {
data['children'] = this.children.map((v) => v.toJson()).toList();
}
return data;
}
}
2、json数据
[
{
"id":"1",
"name":"1楼",
"children":[
{
"id":"0",
"name":"输入区",
"children":[
{
"id":"00",
"name":"A1",
"children":[]
},
{
"id":"01",
"name":"A2",
"children":[]
},
{
"id":"02",
"name":"A3",
"children":[]
},
{
"id":"03",
"name":"A4",
"children":[]
}
]
},
{
"id":"1",
"name":"入库区",
"children":[
{
"id":"10",
"name":"B1",
"children":[]
},
{
"id":"11",
"name":"B2",
"children":[]
}
]
},
{
"id":"2",
"name":"大箱上线区",
"children":[
{
"id":"20",
"name":"C1",
"children":[]
},
{
"id":"21",
"name":"C2",
"children":[]
},
{
"id":"22",
"name":"C3",
"children":[]
},
{
"id":"23",
"name":"C4",
"children":[]
}
]
}
]
},
{
"id":"2",
"name":"2楼",
"children":[
{
"id":"0",
"name":"输入区",
"children":[
{
"id":"00",
"name":"A1",
"children":[]
},
{
"id":"01",
"name":"A2",
"children":[]
},
{
"id":"02",
"name":"A3",
"children":[]
},
{
"id":"03",
"name":"A4",
"children":[]
}
]
},
{
"id":"1",
"name":"入库区",
"children":[
{
"id":"10",
"name":"B1",
"children":[]
},
{
"id":"11",
"name":"B2",
"children":[]
}
]
},
{
"id":"2",
"name":"大箱上线区",
"children":[
{
"id":"20",
"name":"C1",
"children":[]
},
{
"id":"21",
"name":"C2",
"children":[]
},
{
"id":"22",
"name":"C3",
"children":[]
},
{
"id":"23",
"name":"C4",
"children":[]
}
]
}
]
}
]
|