[英]How to set/get variable in Jinja2
I can't understand, why this code is not work: 我不明白,为什么这段代码行不通:
{% set t_c = 'param_1' %}
<div class="col-sm-9">
<select id="category" name="category" class="form-control " required>
<option></option>
{% for c in categories %}
{% if c.id|string == org.category.id %}
{% set t_c = 'param9' %}
<option value="{{ c.id }}" selected>{{ c.name }} </option>
{% else %}
<option value="{{ c.id }}">{{ c.name }} </option>
{% endif %}
{% endfor %}
</select>
</div>
<input id="category_h" name="category_h" type="hidden" value="{{ t_c }}">
Why t_c in last line is 'param_1', when condition {% if c.id|string == org.category.id %} is true? 为什么T_C在最后一行是'PARAM_1',当{如果c.id%|字符串== org.category.id%}条件为真?
Thanks. 谢谢。
UPDATE UPDATE
I have fast solution on JavaScript with jQuery+Select2 like: 我有使用jQuery + Select2的JavaScript快速解决方案,例如:
var category = $("#category"),
category_h = $("#category_h");
category.select2();
category_h.val(category.find("option:selected").text());
t_c = 'param9'
is local to the scope of the for
loop t_c = 'param9'
在for
循环范围内
There are workarounds to extend beyond inner block scope 有一些解决方法可以扩展到内部块范围之外
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.