我在node.js/express+postgresql和ejs中工作。
我想在标记脚本中插入<%=result.dis%>。我从db查询得到的结果。
我试着这样做:
var vPlayer = `<%-JSON.stringify(avg.mark)%>`;
console.log(vPlayer);
或者这个:
const div = document.createElement('div');
div.innerText = `<%=avg.mark %>`
console.log(div);
但这不管用。我的完整代码,我想画一个图表
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<% avg_t.rows.forEach(function(avg){%>
<script type="text/javascript">
var vPlayer = `<%-JSON.stringify(avg.mark)%>`;
console.log(vPlayer);
const div = document.createElement('div');
div.innerText = `<%=avg.mark %>`
console.log(div);
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', vPlayer],
['Mu112', div],
['Onions', 1],
]);
var barchart_options = {
title: 'Barchart: How Much Pizza I Ate Last
Night ',width:400,height:300,legend: '
none '};
var barchart = new google.visualization.BarChart(document.getElementById('barchart_div'));
barchart.draw(data, barchart_options);
}
</script>
<%} ) %>
1条答案
按热度按时间prdp8dxp1#
有两行我完全不懂,但你是这段代码的所有者:
新方法: