如何在多列中循环遍历数组和输出?

时间:2012-10-18 19:46:18

标签: coldfusion

我需要帮助循环浏览我的数据并将其输出到多个列中。目前,它垂直显示在数组中的下一组数据下。请帮忙。

      <cfloop array="#UserAddresses#" index="UA">

                <tr>
                    <td>City: </td>
                    <td><cfif NOT Len(#UA.city.xmlText#)>N/A<cfelse><cfoutput>#UA.city.xmlText#</cfoutput></cfif></td>
                </tr>
                <tr>
                    <td>State: </td>
                    <td><cfif NOT Len(#UA.state.xmlText#)>N/A<cfelse><cfoutput>#UA.state.xmlText#</cfoutput></cfif></td>
                </tr>   
                <tr>
                    <td>Zip Code: </td>
                    <td><cfif NOT Len(#UA.zipcode.xmlText#)>N/A<cfelse><cfoutput>#UA.zipcode.xmlText#</cfoutput></cfif></td>
                </tr>                               
            </cfloop>
    </cfif> 

1 个答案:

答案 0 :(得分:2)

您希望城市,州和邮政编码成为标题吗?然后这将工作

<cfoutput>
    <tr>
        <td>City: </td>
        <td>State: </td>
        <td>Zip Code: </td>
    </tr>
    <cfloop array="#UserAddresses#" index="UA">
        <tr>
            <td><cfif NOT Len(UA.city.xmlText)>N/A<cfelse>#UA.city.xmlText#</cfif></td>
            <td><cfif NOT Len(UA.state.xmlText)>N/A<cfelse>#UA.state.xmlText#<</cfif></td>
            <td><cfif NOT Len(UA.zipcode.xmlText)>N/A<cfelse>#UA.zipcode.xmlText#</cfif></td>
        </tr>                               
    </cfloop>
</cfoutput>

它有效,因为<tr></tr>定义了一个表行,<td></td>定义了该行中的一个单元格。在您的情况下,您正在执行多行而没有单元格,因此您将内容放在列中而不是行中。附注是<cfoutput></cfoutput>每页只应使用一次而不是每个变量。

相关问题