1

查看 google web eng 示例;

{% for greeting in greetings %}
  {% if greeting.author %}
    <b>{{ greeting.author }}</b> wrote:
  {% else %}
    An anonymous person wrote:
  {% endif %}
  <blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}

所以我想要的是:当这个迭代时,我需要以某种方式检查greeting.author 再次检查javascript中存在的一些变量,然后做一些其他的事情。有可能吗?

4

1 回答 1

5
{% for greeting in greetings %}
  {% if greeting.author %}
    <b>{{ greeting.author }}</b> wrote:
  {% else %}
    An anonymous person wrote:
  {% endif %}
  <blockquote>{{ greeting.content|escape }}</blockquote>
  <script type="text/javascript">
     var greeting_author = "{{ greeting.author }}";
     if(greeting_author === someVariable){
        // do other stuff here
     }
  </script>
{% endfor %}

基本上,您可以将变量打印为 js。记住类型(例如将""它们放在字符串周围)。

于 2013-02-17T06:24:29.690 回答