[英]Grails groovy code mixed in the view
Hey.嘿。 I need to do something like this:
我需要做这样的事情:
<td><g:formatDate format="yyyy-MM-dd" date="${it.conference.startDate}"/> (S) <u><g:formatDate format="yyyy-MM-dd" date="${it.conference.endDate}"/></u> (E)<br>
<%
def temp = new Date()
def temp2 = ${it.conference.startDate}
def temp3 = temp - temp2
out << temp3
%>
</td>
But for some reason, this isnt working, and i this the acess: ${it.conference.startDate}
inside groovy code isnt working.但由于某种原因,这不起作用,而我是 groovy 代码中的
${it.conference.startDate}
代码不起作用。 Any help would be apreciated.任何帮助将不胜感激。
Inline code in views is notorious for being a bad design choice.视图中的内联代码因其糟糕的设计选择而臭名昭著。 Generally speaking you'd be better off creating a custom taglib to display your date.
一般来说,您最好创建一个自定义标记库来显示您的日期。 A few immediate benefits from this:
这样做的一些直接好处:
You ought to be able to pretty much drop your existing code into a custom taglib and invoke it without any significant changes.您应该能够将现有代码放入自定义标记库并调用它,而无需进行任何重大更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.