문제

I am displaying results in a table after looping through a query. For TestNumber, there are some results in my query where the number is not present and hence I want to display N/A instead of just blank in the table. So, I am checking the existence using IsDefined, but for some reason it keeps on printing N/A everytime.

<cfloop query="GetMyList1">
    <tr>
        <td align="center">#TestName#</td>
        <cfif IsDefined(TestNumber) >
            <td align="center">#TestNumber#</td>
        <cfelse>
            <td align="center">N/A</td>
        </cfif>
        <td align="center">#Date#</td>
    </tr>
</cfloop>
도움이 되었습니까?

해결책

You would want to check if there is a length of the item. The field exists, so isDefined will always return true

<cfloop query="GetMyList1">
  <tr>
    <td align="center">#GetMyList1.TestName#</td>
    <td align="center"><cfif len(trim(GetMyList1.TestNumber))>#GetMyList1.TestNumber#<cfelse>N/A</cfif></td>
    <td align="center">#GetMyList1.Date#</td>
  </tr>
</cfloop>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top