简体   繁体   English

使Node.js与tree-model-js一起使用

[英]Making Node.js work with tree-model-js

Thanks for the tree-model-js, great lib! 感谢tree-model-js,太棒了! I am new to Node.js and I'm trying to import the tree-model. 我是Node.js的新手,正在尝试导入树模型。 All NPMed successfully. 所有NPMed成功。 I am trying to make Node.js work with your library. 我正在尝试使Node.js与您的库一起使用。 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. 我想这可能是一个Node问题,而不是太多的树模型问题,但是无论如何都要问一下,以防万一需要更改lib。

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? 您是否有示例说明如何在Node中实现此目标?

Essentially I am trying to do this within my main.js Node file but struggling to understand how to access the variables/functions. 本质上,我试图在main.js节点文件中执行此操作,但是努力了解如何访问变量/函数。 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. 请记住,我是Node.js的新手,并且是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. 错误非常简单:未定义TreeModel。

require('tree-model') returns new Node(this.config, model) and in your code, the Node is assigned to variable tm . require('tree-model')返回new Node(this.config, model) ,在您的代码中, Node被分配给变量tm You should use new tm() to instantiate Node or change the variable name to TreeModel 您应该使用new tm()实例化Node或将变量名称更改为TreeModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM