V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
foonnnnn
V2EX  ›  Django

請問這個效果,應該是用Cycle嗎?

  •  
  •   foonnnnn · 2013-05-14 10:33:47 +08:00 · 3224 次点击
    这是一个创建于 4015 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想它在首位的li>class設置active,而尾的li>class設置last.

    <ul>
    <li class='active'><a href='#'><span>Home</span></a></li>
    <li><a href='#'><span>Products</span></a></li>
    <li><a href='#'><span>Company</span></a></li>
    <li class='last'><a href='#'><span>Contact</span></a></li>
    </ul>
    -------------------------------------

    <div id='cssmenu'>
    {% for child in children %}
    {% cycle 'active' 'last' as cssmenu silent %}
    <li class="{{cssmenu}}">
    <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
    {% if child.children %}
    <ul>
    {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
    </ul>
    {% endif %}
    </li>
    {% endfor %}
    </div>
    2 条回复    1970-01-01 08:00:00 +08:00
    Archangel_SDY
        1
    Archangel_SDY  
       2013-05-14 11:35:50 +08:00
    https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

    在循环里面用forloop.first/forloop.last判断吧.
    foonnnnn
        2
    foonnnnn  
    OP
       2013-05-14 13:57:36 +08:00
    成功了!!!!!!!!! 謝謝你!!!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   934 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:21 · PVG 05:21 · LAX 14:21 · JFK 17:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.