简体   繁体   English

是否可以在javascript / jquery函数中使用jinja值

[英]Is it possible to use jinja values in javascript/jquery functions

looking at the google web eng example; 看看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 %}

so what i want is: when this iterates, i need to somehow check greeting.author agains some variable that exists in javascript, and then do some other stuff. 所以我想要的是:当这个迭代时,我需要以某种方式检查greeting.author再次在javascript中存在一些变量,然后做一些其他的东西。 is it possible to do it? 有可能做到吗?

{% 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 %}

Basically, you can just print the variable as js. 基本上,您可以将变量打印为js。 Keep the type in mind (for example put "" around them for strings). 记住类型(例如在字符串周围放置"" )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM