简体   繁体   English

Groovy GSP <g:if>

[英]Groovy GSP <g:if>

This has been driving me crazy for hours and its probably very obvious to someone ... 这让我疯狂了几个小时,对某些人来说可能非常明显......

Can anyone see why this is printing out even though its reporting as being false? 任何人都可以看到为什么这是打印出来,即使它的报告是假的?

<g:if test="${className == 'SRep'}">
    ${className == 'SRep'}
</g:if> 

If classname==SRep then its correct. 如果classname == SRep那么它是正确的。 However if classname <> SRep it still prints out false? 但是如果classname <> SRep仍然打印出false? I don't understand how this can be. 我不明白这是怎么回事。

If I use ?showSource=true, the if statement looks like this: 如果我使用?showSource = true,if语句如下所示:

if(true && ("false")) {
  printHtmlPart(29)
}
else {
  printHtmlPart(30)
}

Anyone see anything obvious? 有谁看到明显的东西?

Thanks John 谢谢约翰

your code looks fine but im not sure what 'className' is, perhaps it's not being returned or returning wrong type etc: 你的代码看起来很好,但我不确定'className'是什么,也许它没有返回或返回错误的类型等:

i would display the output in the GSP of className just to see what it is eg add this anywhere in your GSP: 我会在className的GSP中显示输出,看它是什么,例如在GSP中的任何地方添加:

${className} //displays the value

you may also want to check the object type, in your case i think it should be string so check what you have: 你可能还想检查对象类型,在你的情况下我认为它应该是字符串,所以检查你有什么:

${className?.class} //displays the type of object

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

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