Tree Structures: Suggestions?


#1

Hi All,

I need a library to work with tree structures. Are there any suggestions? I have been trying to use tree-model-js, but I can’t seem to get it to import properly.

import { TreeModel, Node } from 'tree-model' does not seem to work, no idea why. Not sure about release cycles either. Any ideas as to what I can use?

I don’t want to rewrite all the tree traversing functionality. Thanks so much.

Tat

Edit: What is the difference between import { <blah> } from '<path in node_modules>' and var <blah> = require(<blah library>);. It feels like i may have missed something critical here… :frowning:


#2

Not all packages can be extracted like that. If the package only exports one object, in this case TreeModel, you need to import it like this:
import TreeModel from 'tree-model,
which is the same as
var TreeModel = require('tree-model').

Using your first syntax is the same as

var TreeModel = require('tree-model').TreeModel;
var Node = require('tree-model').Node;

But as this package does not export its variables like this, it will not work.