输出产生不需要的空白
我正在输出类别,并在下面列出了子类别。如果每个子类别不是循环中的第一项,则会在其前面添加一个逗号。
另外,我只显示四个结果,因此如果记录计数超过四个,我需要将 ...
附加到第四个循环结果的末尾。
问题是,在应用 ...
的情况下,每个子类别后面都会有一个额外的空格。见下文:
看看逗号前面有一个空格吗?
代码:
<ul class="defaultUL" style="float:right;">
<cfloop query="getParent" startrow="7" endrow="12">
<cfquery name="getSubCategory" datasource="dss">
SELECT Name, ID FROM Category WHERE ParentID = #getParent.ID#
</cfquery>
<cfset SubNumb = getSubCategory.recordcount>
<li><h3><a href="?Page=#Application.Utility.qsEncode(getParent.Name)#">#getParent.Name#</a></h3>
<cfloop query="getSubCategory" startrow="1" endrow="#SubNumb#">
<cfif SubNumb gt 4>
<cfif getSubCategory.currentRow lt 4 AND getSubCategory.currentRow gt 1>
, #getSubCategory.Name#
<cfelseif getSubCategory.currentRow eq 1>
#getSubCategory.Name#
<cfelseif getSubCategory.currentRow eq 4>
#getSubCategory.Name#...
</cfif>
<cfelse>
#getSubCategory.Name#,
</cfif>
</cfloop>
</li>
</cfloop>
</ul>
我确保数据库中的数据末尾没有空格。
I'm outputting categories with subcategories listed underneath. Each subcategory gets a comma prepended to it if it's not the first item in the loop.
Also, I am only displaying four results, so if the record count is more than four, I need to append ...
to the end of the fourth loop result.
The problem is that in instances where ...
has been applied there is an extra space after each subcategory. See below:
See how there is a space before the comma?
Code:
<ul class="defaultUL" style="float:right;">
<cfloop query="getParent" startrow="7" endrow="12">
<cfquery name="getSubCategory" datasource="dss">
SELECT Name, ID FROM Category WHERE ParentID = #getParent.ID#
</cfquery>
<cfset SubNumb = getSubCategory.recordcount>
<li><h3><a href="?Page=#Application.Utility.qsEncode(getParent.Name)#">#getParent.Name#</a></h3>
<cfloop query="getSubCategory" startrow="1" endrow="#SubNumb#">
<cfif SubNumb gt 4>
<cfif getSubCategory.currentRow lt 4 AND getSubCategory.currentRow gt 1>
, #getSubCategory.Name#
<cfelseif getSubCategory.currentRow eq 1>
#getSubCategory.Name#
<cfelseif getSubCategory.currentRow eq 4>
#getSubCategory.Name#...
</cfif>
<cfelse>
#getSubCategory.Name#,
</cfif>
</cfloop>
</li>
</cfloop>
</ul>
I made sure that the data in the database didn't have whitespace at the end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
listAppend
函数构建字符串:Use the
listAppend
function to construct your string:在顶部使用
在底部使用
。然后使用
显式定义应输出到浏览器的内容。Use
<cfsetting enablecfoutputonly="true" />
at the top and<cfsetting enablecfoutputonly="false" />
at the bottom. Then use<cfoutput></cfoutput>
to explicitly define what should be output to the browser.