我<cfoutput>
在表中有一个放置地址变量.我遇到的问题是这些变量有时是null,但由于换行符,它们仍占用表中的空间.
<td>
<cfoutput>
#getMeeting.meetingDemographicsAddressLine1#<br />
#getMeeting.meetingDemographicsAddressLine2#<br />
#getMeeting.meetingDemographicsCity#
</cfoutput>
</td>
Run Code Online (Sandbox Code Playgroud)
<br />
如果变量为null,如何让浏览器忽略标记?
您可以使用cffunction
和创建打印行功能cfif
来检查值的长度是否超过0
确保你实际上也意味着null,请参阅http://www.bennadel.com/blog/1654-Learning-ColdFusion-9-IsNull-And-Working-With-NULL-Values.htm
例子
<cffunction name="PrintLine" returntype="void">
<cfargument name="Value" />
<cfif len(arguments.Value) GT 0>
<cfoutput>#arguments.Value#<br /></cfoutput>
</cfif>
</cffunction>
Run Code Online (Sandbox Code Playgroud)
或从功能返回: -
<cffunction name="PrintLine2" returntype="string">
<cfargument name="Value" />
<cfset var foo = "" />
<cfif len(trim(arguments.Value)) GT 0>
<cfset foo = arguments.Value & "</br />" />
</cfif>
<cfreturn foo />
</cffunction>
Run Code Online (Sandbox Code Playgroud)
(可选)根据需要添加返回类型/提示/必需属性
文档
请参阅http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_f_21.html
和
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_i_01.html
你可以这样做: -
<td>
<cfoutput>
#PrintLine(getMeeting.meetingDemographicsAddressLine1)#
#PrintLine(getMeeting.meetingDemographicsAddressLine2)#
#getMeeting.meetingDemographicsCity#
</cfoutput>
</td>
Run Code Online (Sandbox Code Playgroud)