因此,我试图使一个变量始终接收一个新值和过去的值。有没有办法对mySQL返回的对象执行类似的操作?像这样:SQL-{10,11,20}
在循环中,变量应保留收到的过去值并添加新值。 为{ 可变-10 可变-10,11 可变-10,11,20 }
是的,我是一名学生,没有找到可行的方法。我尝试了级联,但是没有用。
<% for (var i = 0; i < barras.length; i++){ %>
barras = <%= JSON.parse(barras[i].progresso)%> + "," + <%=
JSON.parse(barras[i].progresso)%> ;
<%}%>
视图文件:
<!DOCTYPE html>
<html>
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<% if(barras){ %>
<ul>
<% for (var i = 0; i < barras.length; i++) { %>
<li>
<%= JSON.parse(barras[i].progresso) %>
</li>
<%}%>
</ul>
<% } %>
<div id="myDiv" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
<% if(barras){ %>
<% for (var i = 0; i < barras.length; i++){ %>
barras = <%= JSON.parse(barras[i].progresso)%> + "," + <%= JSON.parse(barras[i].progresso)%> ;
<%}%>
<% } %>
data = [{
type: 'bar',
x: [barras],
y: 'teste',
orientation: 'h'
}];
console.log(barras);
Plotly.newPlot('myDiv', data);
</script>
</body>
</html>
此视图的路线:
app.get('/barras', function(req,res){
console.log('Database connection online');
connection.query('select progresso,nome from barra', function(error,result){
barras = result;
console.log(barras);
res.render('admin/barras',barras);
});
});