V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Tornado Documentation
http://www.v2ex.com/tornado/
Tornado on GitHub
https://github.com/facebook/tornado/
Tornado Gists
http://tornadogists.org/
paulguo
V2EX  ›  Tornado

请教一个Tornado框架模板中循环的问题。

  •  
  •   paulguo · 2012-07-11 23:24:58 +08:00 · 5453 次点击
    这是一个创建于 4278 天前的主题,其中的信息可能已经有所发展或是发生改变。
    {% for i in data %}
    ...
    <div class="">
    </div>
    {% end %}

    如何每隔一条输出一个className标志?
    7 条回复    1970-01-01 08:00:00 +08:00
    Brutal
        1
    Brutal  
       2012-07-11 23:28:11 +08:00
    {% set i = 1%}
    <div class="{% if i % 2 == 0 %} className {% end %}">
    ...

    {% set i = i + 1 %}
    paulguo
        2
    paulguo  
    OP
       2012-07-11 23:29:28 +08:00
    @Brutal thanks.
    yoyicue
        3
    yoyicue  
       2012-07-11 23:33:46 +08:00
    paulguo
        4
    paulguo  
    OP
       2012-07-11 23:53:52 +08:00
    @yoyicue 确实,tornado自带的的确有点弱,未定义的变量都没法检测,还要try。
    CoX
        5
    CoX  
       2012-07-12 00:18:28 +08:00   ❤️ 1
    {% for idx,item in enumerate(data) %}
    ...
    <div class="{% if idx % 2 == 0 %} className {% end %}">
    </div>
    {% end %}
    paulguo
        6
    paulguo  
    OP
       2012-07-12 13:25:05 +08:00
    @Cox thanks~ 这样好很多
    hartnett
        7
    hartnett  
       2013-01-07 12:26:11 +08:00
    thx,不错的方法。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3555 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:48 · PVG 12:48 · LAX 21:48 · JFK 00:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.