当前位置: 代码迷 >> JavaScript >> django template: 输出js数组加逗号的有关问题
  详细解决方案

django template: 输出js数组加逗号的有关问题

热度:1246   发布时间:2012-11-23 22:54:33.0
django template: 输出js数组加逗号的问题
Django template输出js数组时:
引用
{% for val in list %}
{{ val }},
{% endfor %}

这样会导致最后一个元素也带逗号,在IE6上会报js错误。

引用
{% for val in list %}
{% if not forloop.first %}, {% endif %}
{{ val }}
{% endfor %}

用forloop.first判断一下,这样就解决了。

  相关解决方案