1

在我的模板 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]

任何的想法?

4

1 回答 1

3
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,  ...
于 2012-04-19T08:52:46.693 回答