[英]Java JTwig For Loop Using A Range Not Container
I want to be able to do the equivalent of the following loop using a JTwig template: 我希望能够使用JTwig模板执行以下循环的等效操作:
for (int i = 0; i < length; i++ ) { ... }
I have tried the following but neither seem to work: 我尝试了以下但似乎都没有工作:
{% set k = 10 %}
{% for i in 1..k %}
<option value={{k}} >{{k}}</option>
{% endfor %}
Or 要么
{% set k = 10 %}
{% for i in range(1,k) %}
<option value={{k}} >{{k}}</option>
{% endfor %}
I can loop containers but can't seem to find a way of getting this kind of thing to work. 我可以循环容器,但似乎无法找到让这种东西工作的方法。
You have to add square brackets, like so: 你必须添加方括号,如下所示:
{% for i in [1..10] %}
{{ i }}
{% endfor %}
I discovered this rather by accident. 我偶然发现了这一点。 It seems to be missing from the documentation.
它似乎从文档中遗漏了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.