2015-01-17 2 views
1

Я не могу понять, почему этот код не работает:Как установить/получить переменную в Jinja2

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

Почему T_c в последней строке «param_1», когда условие {%, если с. id | string == org.category.id%} истинно?

Спасибо.

UPDATE

У меня есть быстрое решение на JavaScript с JQuery + выбор2 как:

var category = $("#category"), 
     category_h = $("#category_h"); 

category.select2(); 
category_h.val(category.find("option:selected").text()); 

ответ

Смежные вопросы