简体   繁体   English

Grails g:if = null不起作用

[英]Grails g:if = null not working

I've been trying to put some if logic into my grails _form.gsp. 我一直在尝试在_form.gsp文件中添加一些if逻辑。 Basically I want it to add an extra line to a table if model I'm passing in is null, but its not working! 基本上,如果我要传递的模型为null,但我希望它在表中添加额外的一行,但是它不起作用!

I have this: - 我有这个: -

<g:if test="${results = null}">
    banana
</g:if>

And it does nothing. 它什么也没做。 I tried: - 我试过了: -

<g:if test="${results.isEmpty()}">

But that causes the page to error on load with the message: - 但这会导致页面在加载时出错并显示以下消息:-

Cannot invoke method isEmpty() on null object

If I try the reverse logic with <g:if test="${results != null}"> this works absolutely fine in scenarios where I know the model being passed in isn't empty! 如果我使用<g:if test="${results != null}">尝试反向逻辑, <g:if test="${results != null}">在我知道传入的模型不为空的情况下,这绝对可以正常工作! What am I missing? 我想念什么?

you need a double "==" for your if statement: 您的if语句需要双“ ==”:

<g:if test="${results == null}">
                       ^
                       |

Since its Grails.. 自从Grails ..

<g:if test="${ !results }">

would also work.. Just a shorter version 也会工作..只是一个较短的版本

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

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