Reputation: 45
My problem is that when i send data to handlebars template it converts my array of strings to array of variables:
res.render('index', {
title: 'Express' ,
chartT:"title",
lab:['test','test2','test3'],
dat:[1,3,5]
});
Template code:
<canvas id="myChart" width="400" height="400"></canvas>
<script>
var pollOptions = [{{{lab}}}];
var pollData = [{{{dat}}}];
createChart("mychart",pollOptions,pollData);
</script>
And the problem that in pollOptions i got this
var pollOptions = [test,test2,test3];
Uncaught ReferenceError: test is not defined
I don't know why the template convert them...
Thank you in advance for your help.
Upvotes: 0
Views: 2248
Reputation: 45
Ok I have figured it out!
var rawData = "{{{lab}}}";
var pollData = rawData.split(",");
And now i can use it as a string array
Upvotes: 0
Reputation: 820
HandleBars
dedicated to HTML templating (Not to render a JS variable)
You can do something like this (Without handlebars):
var pollOptions = ["{{{lab}}}"];
var pollData = ["{{{dat}}}"];
Upvotes: 1