准备好在文档上访问primefaces widgetvars [英] Access to primefaces widgetvars on document ready

查看:79
本文介绍了准备好在文档上访问primefaces widgetvars的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图像这样访问文档中的素面组件:

Im trying to access to primefaces components on document ready like this:

$(function() {
  var showDialog = getUrlParameter("showDialog");
  if (showDialog == "true") {
    PF('myDialog').show();
  }
});

但是在那一刻,primefaces widgetvars不可用,并且出现以下错误:

But in that moment the primefaces widgetvars are not available and I get the following error:

var'myDialog'的小部件不可用!

Widget for var 'myDialog' not available!

在PrimeFaces 6.2和7.0(可能还有一些早期版本)中,您得到的错误是

In PrimeFaces 6.2 and 7.0 (and maybe some earlier versions) the error you get is

TypeError:PF(...)未定义

TypeError: PF(...) is undefined

,但是当使用PrimeFaces.widgets['myDialog'].show()代替PF('myDialog').show();时,错误是可比较的

but when PrimeFaces.widgets['myDialog'].show() is used instead of PF('myDialog').show(); the error is comparable

TypeError:PrimeFaces.widgets.myDialog未定义

TypeError: PrimeFaces.widgets.myDialog is undefined

何时可以访问primefaces widgetvar?

When are the primefaces widgetvars ready to be accessed?

推荐答案

我为我的案件找到了更好的解决方案.我使用h:body

I found a better solution for my case. I call a JavaScript method using the onload attribute of h:body

<h:body onload="checkIfShowDialog()">

这是JavaScript方法:

And this is the JavaScript method:

function checkIfShowDialog(){
  var showDialog = getUrlParameter("showDialog");
  if (showDialog == "true") {
    PF('myDialog').show();
  }
}

这可以按需工作.

这篇关于准备好在文档上访问primefaces widgetvars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆