Monday, 12 June 2017

How could I retrieve data from JSON objects to use it in .hbs templates

First, I've converted a CSV file to JSON using npm-csvtojson using the following code:

csv()
.fromFile(csvFilePath)
.on('json', (jsonObj) => {
// combine csv header row and csv line to a json object 
// jsonObj.a ==> 1 or 4
console.log(jsonObj);

.on('done',(error)=>{
console.log('end');
})

The console.log(jsonObj) result is:

{ FECHA: '2017-01-01 14:00:00', IDVARIABLE: '3', DATO: '123' }
{ FECHA: '2017-01-01 14:00:00', IDVARIABLE: '4', DATO: '52154' }
{ FECHA: '2017-01-01 14:00:00', IDVARIABLE: '7', DATO: '7.4' }
{ FECHA: '2017-01-01 14:00:00', IDVARIABLE: '11', DATO: '7.70' }

And then, I need to put this data in a .hbs template like this

<td style="border: 1px solid #000;">**</td>
<td style="border: 1px solid #000;">**</td>
<td style="border: 1px solid #000;">**</td>

How could I do this?



via Juan Pablo TM

No comments:

Post a Comment