[英]Showing error message Grails - Bootstrap
從我的grails Controller類中,我需要顯示GSP文件中的錯誤消息。
def myControllerMethod() {
if (fruit==apple){
// Do something
} else {
Show the error message, from the GSP file.
}
}
在GSP文件中。 我有以下代碼,這是我要顯示5秒鍾的錯誤消息,然后它應該消失。
<body>
...
<div class="alert alert-danger" role="alert">
<a href="#" class="alert-link">...</a>
</div>
</body>
為此,您需要Javascript / JQuery。 下面是一個例子:
setTimeout( function(){
$('div.alert').fadeOut("slow"); },
5000 );
有關setTimeout的更多信息,請點擊此處
您還可以使用delay()(更多信息在此處 )
例:
def myController() {
def message
if (fruit==apple){
// Do something
} else {
message = 'Your message'
}
return [message:message, ...]
}
您認為:
<g:if test="${ message }">
...
</g:if>
並且不要忘記啟用警報:
$(".alert").alert()
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.