14

我想在 if 语句中按键获取元素的值。

例子:

作品:

{{ example[5] }}

不起作用:

{% if example2 is example[5] %} something ... {% endif %}

抛出异常:

值“[”的意外标记“标点符号”(预期为“语句块结束”)

非常感谢你

亲切的问候

4

2 回答 2

19

代替

{% if example2 is example[5] %} something ... {% endif %}

尝试将 'is' 更改为 '=='

{% if example2 == example[5] %} something ... {% endif %}
于 2012-06-24T22:07:29.353 回答
10

也许您应该使用该attribute函数来获取对象或数组值。此链接可能对您有所帮助

于 2013-03-14T14:44:27.453 回答