简体   繁体   English

Nodejs 自定义 class 不会在车把中呈现

[英]Nodejs custom class won't render in handlebars

I apologise in advance for what is probably a really obvious fix..我提前为可能是一个非常明显的修复道歉..

I'm trying to render the output from an mssql stored procedure (multiple recordsets) in nodejs using handlebars.我正在尝试使用把手从 nodejs 中的 mssql 存储过程(多个记录集)呈现 output。

(Also NOT a JS coder, or a coder really) (也不是 JS 编码器,也不是真正的编码器)

Challenge 1: The SP provides data in a column format, while the graph plugin requires an array for label,x,y..挑战一:SP 以列格式提供数据,而图形插件需要 label,x,y..的数组。

I though I solved this with a custom class with 3 arrays..虽然我用自定义 class 和 3 arrays 解决了这个问题。

 class myClass{ #X = []; #Y = []; #Label = []; get X { return #X; } get Y { return #Y; } get Label { return #Label; } Add(x,y,label){ #X.push(x); #Y.push(y); #Label.push(label); } }
But I'm getting something weird (but probably obvious).. 但我得到了一些奇怪的东西(但可能很明显)..

The query returns data as expected and I can loop over it creating a new myClass for each recordset and then adding the values into the arrays, I can also access each property through console.log.查询按预期返回数据,我可以循环遍历它,为每个记录集创建一个新的 myClass,然后将值添加到 arrays,我还可以通过 console.log 访问每个属性。

What I can't do is send the object as whole to console, it prints as {myClass {}}.我不能做的是将 object 整体发送到控制台,它打印为 {myClass {}}。

Challenge 2: It won't render through handlebars挑战 2:它不会通过把手渲染

I suspect that 1 is causing the other, but simply don't know enough to stay for sure.我怀疑 1 导致了另一个,但根本不知道足以确定。

Any help gratefully received:)感激地收到任何帮助:)

Fixed it解决它

DON'T USE PRIVATE PROPERTIES...不要使用私有财产...

Neither Handlebars or console.log use the get() function, so if it's private they can't see it... Handlebars 或 console.log 都没有使用 get() function,所以如果它是私有的,他们就看不到它......

If you have a similar issue, I hope this helps.如果您有类似的问题,我希望这会有所帮助。

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

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