0
上下文名單在我看來,我通過上下文的模板,其中包含的(X,Y)的二維座標列表:索引模板
_points = [[100, 100], [200, 200], [300, 200]]
context = {'points': _points}
return render(request, 'mytemplate.html', context)
在我的模板,我想繪製這些點之間的線路:
var c = document.getElementById("graph"); // "graph" is a canvas element
var ctx = c.getContext("2d");
ctx.beginPath();
// Move to the first point
ctx.moveTo({{ points[0][0] }}, {{ points[0][1] }});
// Loop through all points and draw connecting line
{% for point in points %}
ctx.lineTo({{ point[0] }}, {{ point[1] }});
{% endfor %}
ctx.stroke();
但是,我上線的錯誤:
ctx.lineTo({{ point[0] }}, {{ point[1] }});
說Could not parse the remainder: '[0]' from 'point[0]'
。
什麼是正確的方法是從上下文索引列表變量?