0

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

      <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> 
4

1 回答 1

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>每页只能使用一次,而不是围绕每个变量。

于 2012-10-18T20:00:35.303 回答