给出格式为{Name:[Type,Definition,Order]}
的列表值字典,如下所示:
{% set data = {
'Customer' : ['Form', 'Customer is module for .... etc.', '1'],
'Salutation' : ['Label', 'A greeting in words or actions or the words used at the beginning of a letter or speech.', '2'],
'First Name English': ['Label', 'The name that was given to you when you were born', '3']
} %}
我想通过键Order
来循环字典和顺序,正如我所记录和question thread here那样
{% for key,value in data.iteritems()|sort(attribute=value[2]) %}
{% if not key=='Name' %}
<div class="item">
<h3 class="item-head item-name tags" contenteditable="true" style="float: left;">{{key}}</h3>
<h3 class="item-label" style="float: left;margin-left: 10px;">{{value[0]}}</h3>
<p class="item-def" style="clear: both;" contenteditable="true">{{value[1]}}</p>
</div>
{% endif %}
{% endfor %}
但是由于错误而未能成功。所以,无论如何,我可以通过用Order
对字典进行排序来循环字典吗?谢谢