这是我的问题。PictureLenth是我的图片数组长度,ProductImage是一个列表。现在无法使用将数组地址指向ProductImage。如何在{{}}上使用javascript变量?在
lenth = {{ PictureLenth }}-1;
now = 0;
function t_setInterval() {
window.intervalParam = window.setInterval(function() {
var date = new Date();
if (lenth>now)
{now = now + 1;}
else
{now = 0;}
var img = document.getElementById("image");
img.src="data:image/png;base64, {{ ProductImage[now] }}";
return false;
}, 4000);
}
这是因为Jinja在服务器端运行时不能访问} filter 将
now
,当JavaScript在客户端运行时,字符串是静态的,永远不会改变。解决方案是使用Flask's ^{ProductImage
作为JavaScript变量提供:相关问题 更多 >
编程相关推荐