janez89 / mongoose-materialized

mongoose materialized plugin
59 stars 22 forks source link

Retrieve all elements as "tree view" #15

Open bora89 opened 9 years ago

bora89 commented 9 years ago

Hi, thank you for the great plugin!

Could you please show how to extract all items for the select input but with indentation? Something like that: root -sub cat --sub sub cat

Currently, I have recursive function:

function iterate(current) {
    if (!current) return;
    console.log(current.name);
    if (current.hasOwnProperty('children')) {
        var children = current.children;
        for (var i = 0, len = children.length; i < len; i++) {
            iterate(children[i]);
        }
    }
}

So, needs list of elements which looks like tree (with information about deepness of course)

janez89 commented 9 years ago

Hy, Unfortunately, it must be flatten the tree.

Later it I will show an example.