传递数组来查看没有html编码的问题node js(handlebars)

我打电话给正在返回csv的雅虎财务API。 然后,我想将csv文件转换为Google图表可以读取的数组。 问题是当我传递数组到视图时,它有一堆html编码的字符。

例如,我想传递数组:

[['Year', 'Sales', 'Expenses'],['2004',1000,400],['2005',1170,460],['2006',660,1120],['2007',1030,540]] 

但是,当页面呈现时,它正在抛出一个错误,传递的数组看起来像这样:

 [['Year', 'Sales', 'Expenses'],['2004',1000,400],['2005',1170,460],['2006',660,1120],['2007',1030,540]] 

这是我的index.js:

 var router = require('express').Router(); function GetCompanyInformation(callback) { var request = require('request'); request('http://table.finance.yahoo.com/table.csv?s=orcl&a=0&b1&c=2010&d=0&e=1&f=2011&g=d&y=0&z=orcl', function (error, response, data) { if (!error && response.statusCode == 200) { return callback(null,data); } return callback('An error has occurred.',null); }) } /* GET home page. */ router.get('/', function(req, res, next) { GetCompanyInformation(function(err, data){ res.render('index', { title: 'Express', data : "[['Year', 'Sales', 'Expenses'],['2004',1000,400],['2005',1170,460],['2006',660,1120],['2007',1030,540]]" }); }); }); module.exports = router; 

这是我的看法:

 <div class="container"> <div class="row"> <h1>{{ title }}</h1> <hr> <div id="stock-chart-container" class="col-lg-12"> <h3>Item Name</h3> <hr> <div id="company-performance-chart"></div> </div> </div> </div> <script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable({{data}}); var options = { chart: { title: 'Company Performance', subtitle: 'Sales, Expenses, and Profit: 2014-2017', } }; var chart = new google.charts.Bar(document.getElementById('company-performance-chart')); chart.draw(data, options); } <!--RESIZE THE GOOGLE CHART (MAKES IT RESPONSIVE)--> $(window).resize(function(){ drawChart(); }); </script> 

需要传递给Google图表的值需要如下所示:

 var data = google.visualization.arrayToDataTable([ ['Year', 'Income', 'Expenses', 'Profit'], ['2014', 1000, 400, 200], ['2015', 1170, 460, 250], ['2016', 660, 1120, 300], ['2017', 1030, 540, 350] ]); 

我以错误的方式接近了吗?

@James当我把它作为一个数组传递给我在渲染的视图中:

 var data = google.visualization.arrayToDataTable(Year,Sales,Expenses,2004,1000,400,2005,1170,460,2006,660,1120,2007,1030,540);