DenQ / list-to-tree

Convert list to tree
BSD 3-Clause "New" or "Revised" License
87 stars 30 forks source link

Mongodb find Search results Generate only a root node #9

Closed xpsion closed 7 years ago

xpsion commented 7 years ago

uMode.find({}, (err,data) => { let ltt = new LTT(data, { key_id: 'id', key_parent: 'parent' }); let tree = ltt.GetTree(); console.log(tree); }

DenQ commented 7 years ago

@xpsion , What's in a data? Give an example, please

xpsion commented 7 years ago

[{ "id" : 6000, "parent" : 0 } { "id" : 6001, "parent" : 6000 } { "id" : 6002, "parent" : 6000 } { "id" : 6003, "parent" : 6000 } { "id" : 6004, "parent" : 6000 } { "id" : 6005, "parent" : 6000 } { "id" : 6006, "parent" : 6000 } { "id" : 6007, "parent" : 6000 } { "id" : 6008, "parent" : 6001 }]

xpsion commented 7 years ago

data = JSON.parse(JSON.stringify(data));

Finally It Has Worked!
Why need this conversion?

DenQ commented 7 years ago

@xpsion , I checked your data and created PR - https://github.com/DenQ/list-to-tree/pull/10 All working without convertation and passed tests

xpsion commented 7 years ago

thank you~ Strange, why use mongoose find results can not directly use