简体   繁体   中英

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.

(Also NOT a JS coder, or a coder really)

Challenge 1: The SP provides data in a column format, while the graph plugin requires an array for label,x,y..

I though I solved this with a custom class with 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.

What I can't do is send the object as whole to console, it prints as {myClass {}}.

Challenge 2: It won't render through handlebars

I suspect that 1 is causing the other, but simply don't know enough to stay for sure.

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...

If you have a similar issue, I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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