如何在 messages.properties 文件中的外部Java脚本文件上设置错误消息,以便错误消息将根据本地或语言(例如英语,德语等)自动更改。
我如何在外部Java脚本文件上使用 <g:message code="" default="" />
或 ${message(code:'',default:'')}
?
最佳答案
在我的应用程序中,我通过以下方式将模型对象传递给javascript:
<g:javascript>
// Scroll the page to the position of the add button clicked by the user
jQuery(document).ready(function() {
window.scrollBy(0, ${pageScroll});
});
</g:javascript>
在您的示例中,您可以使用标签定义一个新变量
<g:set var="tranlsatedLabel" value="${g.message(..)}"/>
您可以像上面显示的那样通过它。
关于javascript - Grails从外部JavaScript文件中的messages.properties设置错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288937/