Thanks for the tree-model-js, great lib! I am new to Node.js and I'm trying to import the tree-model. All NPMed successfully. I am trying to make Node.js work with your library. I guess it is as much a Node question and not so much tree-model issue, but asking anyway just in case the lib needs to be changed for it.
I have the following:
var tm = require('tree-model');
//all good so far.
but when I am trying to recreate the code that works on my webpage
//is this how I access it?
tm.tree = new TreeModel();
it is giving me an error. Do you have any examples on how this can be achieved in Node?
Essentially I am trying to do this within my main.js Node file but struggling to understand how to access the variables/functions. It all works well when on a webpage when I do the following:
tree = new TreeModel();
root = tree.parse({ name: "Ben and Jerry" });
Any examples much appreciated. Please keep in mind that I am new to Node.js and somehow rookie on javascript. I learn better from examples so feel free to point me in the right direction.
The error is quite simple: TreeModel is not defined.
require('tree-model')
returns new Node(this.config, model)
and in your code, the Node
is assigned to variable tm
.
You should use new tm()
to instantiate Node
or change the variable name to TreeModel