使用 Javascript 显示咆哮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25498449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show growl using Javascript
提问by Abdennour TOUMI
I want to display a growl in client-side using Javascript.
我想使用 Javascript 在客户端显示咆哮。
I mean this UI-component:
我的意思是这个 UI 组件:
I found this thread, However , I can't find an object called :topBar
我找到了这个线程,但是,我找不到名为的对象:topBar
Known also that using:
也知道使用:
grep -rl
to find text in files leads to discover this JS :
grep -rl
在文件中查找文本会导致发现这个 JS:
/**
* PrimeFaces NotificationBar Widget
*/
PrimeFaces.widget.NotificationBar = PrimeFaces.widget.BaseWidget.extend({
init: function(cfg) {
this._super(cfg);
var _self = this;
//relocate
this.jq.css(this.cfg.position, '0').appendTo($('body'));
//display initially
if(this.cfg.autoDisplay) {
$(this.jq).css('display','block')
}
//bind events
this.jq.children('.ui-notificationbar-close').click(function() {
_self.hide();
});
},
show: function() {
if(this.cfg.effect === 'slide')
$(this.jq).slideDown(this.cfg.effect);
else if(this.cfg.effect === 'fade')
$(this.jq).fadeIn(this.cfg.effect);
else if(this.cfg.effect === 'none')
$(this.jq).show();
},
hide: function() {
if(this.cfg.effect === 'slide')
$(this.jq).slideUp(this.cfg.effect);
else if(this.cfg.effect === 'fade')
$(this.jq).fadeOut(this.cfg.effect);
else if(this.cfg.effect === 'none')
$(this.jq).hide();
},
isVisible: function() {
return this.jq.is(':visible');
},
toggle: function() {
if(this.isVisible())
this.hide();
else
this.show();
}
});
回答by Hatem Alimam
The component you are referring to is Growl, in the client-side it's represented by PrimeFaces.widget.Growl
which has renderMessage
function to render a single growl message.
您所指的组件是 Growl,在客户端由它表示,PrimeFaces.widget.Growl
它具有renderMessage
呈现单个咆哮消息的功能。
Assuming you have already defined a growl component in your page with a widgetVar name:
假设您已经在页面中使用 widgetVar 名称定义了一个咆哮组件:
<p:growl widgetVar="growlWV" />
Now in javascript
现在在 javascript 中
PF('growlWV').renderMessage({"summary":"summary goes here",
"detail":"detail goes here",
"severity":"warn"})
The severity are obviously three types :
严重程度明显分为三种:
info
warn
error
信息
警告
错误
回答by Sergio Soto
This worked for me with primefaces:
这对我有用primefaces:
<script type="text/javascript">
function validateSearch(){
PF('growlWV').init({'msgs':'"summary":"Select a State Medical Unit or Demographic Capture Date", "severity":"info" ',
"life":"9000"})
}
}
You can see the methods here: https://searchcode.com/codesearch/view/2686099/
您可以在此处查看方法:https: //searchcode.com/codesearch/view/2686099/