zoukankan      html  css  js  c++  java
  • webwork遍历数组标签

    WebWork中提供了一个<ww:iterator></ww:iterator>标签用于遍历数组。

    01

    如果数组中是普通类型,比如String、int等类型,可以通过标签中的id属性去获取数组中的元素。

    <ww:iterator id="period" value="periods" status="status">
        <ww:property value="#period">
    </ww:iterator>

    这里的id就相当于一个变量,可以这么简单理解,通过【#】符号+变量名来访问该变量。

    02

    如果数组中是数组类型,那么和上面的用法其实差不多,可以用下标去访问数组中的数组元素。

    <ww:iterator id="period" value="periods" status="status">
        <ww:property value="#period[0]">
        <ww:property value="#period[1]">
        <ww:property value="#period[2]">
    </ww:iterator>

    通过下标访问符就能轻松访问数组中的数组元素。

    03

    如果数组中是对象类型,则可以直接配合<ww:property></ww:property>标签获取对象中的属性,而不需要标签中的id属性。

    <ww:iterator value="periods" status="status">
        <ww:property value="periodName">
    </ww:iterator>

    这里的periodName就是period对象的一个属性。

    04

    另外,标签中的status属性也可以在一些场景中排上用场。

    #status.odd 是否奇数行
    #status.even 是否偶数行
    #status.count 当前行数
    #status.index 当前行的序号,从0开始,#status.count=#status.index+1
    #status.first 是否第一行
    #status.last  是否最后一行
    #status.modules(int) 当前行数取模

    这个技术可以说比较老旧了,只是最近在维护老项目用上了,所以这里特别记录一下。

    "我要用什么样的速度行走在路上,才能再次和你相遇。"

  • 相关阅读:
    CareerCup Questions List 职业杯题目列表
    [CareerCup] Guards in a museum 博物馆的警卫
    [LeetCode] 7. Reverse Integer 翻转整数
    Python笔记11------一个K-means聚类的小例子
    python笔记10-----便捷网络数据NLTK语料库
    Python笔记9-----不等长列表转化成DataFrame
    Python笔记8----DataFrame(二维)
    Python笔记7----Pandas中变长字典Series
    Python笔记6----数组
    Python笔记5----集合set
  • 原文地址:https://www.cnblogs.com/yanggb/p/11579295.html
Copyright © 2011-2022 走看看