在我的模板 Twig 中,我希望在 javascript 中使用循环,所以我尝试了这个但它不起作用:
series: [{
name: 'Population',
data: [{% for SoResult in SoResults %} SoResult.pollanswerPoints {% endfor %}],
dataLabels: {
enabled: true,
我有这个错误:
missing ) after argument list
[Stopper sur une erreur]
SoResult.pollanswerPoints
我想要这样的东西:
data : [44,58,69]
有什么想法吗?
最佳答案
series: [{
name: 'Population',
data: [
{% for SoResult in SoResults %}
{# write a comma to separate elements unless it is first one... #}
{% if loop.index0 != 0 %},{% endif %}
{# it's important to write quotes if elements are string in Javascript #}
"{{SoResult.pollanswerPoints}}"
{% endfor %}
],
dataLabels: {
enabled: true, ...
关于javascript - javascript中的代码 Twig ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10221055/