javascript - javascript中的代码 Twig

标签 javascript symfony

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

相关文章:

symfony - 管理归档表单和结果页面的最佳方式

ios - Bootstrap 不适用于 Mini Opera (iOS)

php - SwiftMailer - PHP - 如何禁用 ssl 证书验证

javascript - 通过 jQuery 写入 JSON 数据

javascript - 如何阻止谷歌验证码执行?

javascript - 是 var { Route, Redirect, RouteHandler, Link } = Router;在 Javascript 中有效吗?

rest - FOS REST 包上的动态序列化组

javascript - 单击按钮播放全屏视频

javascript - 在 TypeScript 中从 Promise.all 返回正确的类型

sql - Doctrine 中两列的唯一值