0

I need to call a function passing response rendered to a express-handlebars page. How can I do this?

This my controller and it is rendering result to a handlebars page.

    return servico.obterMetricasStatusCode()
    .then((resultado) => {
        res.status(200).render('erros', {
            resultado: resultado
        })
    });

At handlebars file I have a div with id "chart_div" where I need to put a google chart so I need to call a function that execute this:

var data = google.visualization.arrayToDataTable(resultado);

where the variable called "resultado" is the data to generate the chart but resultado is always undefined when this line is executed.

If I put {{resultado}} inside div the object is printed in screen correctly.

Can I help me?

Rodrigo Rocha
  • 387
  • 1
  • 4
  • 14

1 Answers1

0

If you are trying to render the returned data, that is accomplished in the view, using your engine. if you are just wanting the data returned so that you can manipulate it, I think you want to use res.json(resultado) or res.send(resultado)

Jay Hamilton
  • 114
  • 5
  • Thanks Jay Hamilton! I need to send result to manipulate it in front end function but I need to render to the page too. – Rodrigo Rocha Oct 13 '17 at 19:34