简体   繁体   English

Grails GSP中的空间

[英]Space in grails GSP

Sorry grails / gsp noob here. 对不起grails / gsp noob在这里。 I am trying to fix a bug where a space is always inserted before some text. 我试图修复一个错误,在某些文本之前总是插入一个空格。

The text is just displayed based on a else if: 如果出现以下情况,则仅基于else显示文本:

<g:elseif test="${index > 0 && merch <= transaction.Transactions.size() - 2}">
, ${trans.name}
</g:elseif>

A space is always displayed before the comman. 在指挥员之前总是显示一个空格。 Why? 为什么? How do I get rid of the space? 我如何摆脱空间?

Why? 为什么?

Because there's white space (the newline) between the opening elseif tag and the comma. 因为在开头的elseif标记和逗号之间有空格(换行符)。

How do I get rid of the space? 我如何摆脱空间?

Put the comma directly after the opening tag rather than on the next line. 将逗号直接放在开始标记之后,而不是放在下一行。 You can achieve this by moving the newline inside the tag rather than after it: 您可以通过在标记内而不是在标记之后移动换行来实现此目的:

<g:elseif test="${index > 0 && merch <= transaction.Transactions.size() - 2}"
  >, ${trans.name}</g:elseif>

or by using a comment 或者通过评论

<g:elseif test="${index > 0 && merch <= transaction.Transactions.size() - 2}"><%--
  --%>, ${trans.name}<%--
--%></g:elseif>

You may find you need to use a similar trick to squash the space between the </g:if> and the <g:elseif> tags, and immediately before the <g:if> . 您可能会发现需要使用类似的技巧来压缩</g:if><g:elseif>标记之间的空格,并紧接在<g:if> If this all starts to look a bit unwieldy you may prefer to use Groovy code rather than GSP tags for the conditionals 如果这一切看起来有点笨拙你可能更喜欢使用Groovy代码而不是GSP标签用于条件

stuff before<%
if(something) {
  %>some content<%
} else if(index > 0 && merch <= transaction.Transactions.size() - 2) {
  %>, ${trans.name}<%
} else {
  %>something else<%
}
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM