如何找到一个widgetVar? [英] How to find a widgetVar?

查看:100
本文介绍了如何找到一个widgetVar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有素面组件,例如

If i have a primefaces component, like

<p:selectOneMenu id="myComponent">
...
</p:selectOneMenu>

在html中,它将生成如下内容:

In the html, it will generate something like this:

<div id="myFormName:myComponent" widgetVar="lollipop">
...A lot of things in here...
</div>
<script id="myFormName:myComponent_s">
   $(function(){PrimeFaces.cw('SelectOneMenu','lollipop',.......
</script>

在script标签内,您会注意到小部件的var名称(如果我未在组件中提供它,它将被生成). 我想知道如何获取小部件var元素,或者如果不可能,如何获取该"标记,以便获取此小部件var的名称.

Inside the script tag, you can notice the widget var name(if i dont provide it in the component, it will be generated). I want to know how can i get the widget var element, or if this is not possible, how can i get that "" tag so i can get the name of this widget var.

------编辑------ 我将尝试解释为什么我需要这个. 我有这个功能:

------ EDIT ------ I will try to explain why i need this. i have this function:

function simulaTabManoBrow(event){
    var focusedComponent=document.activeElement;
    if(event.keyCode==13){
        //Cancel th edefault enter event(submit the form)
        event.preventDefault();
        event.stopPropagation();
        event.returnValue = false;
        event.cancelBubble = true;
        if((focusedComponent.tagName.toLowerCase()=="input" && focusedComponent.type.toLowerCase()=="button") || focusedComponent.tagName.toLowerCase()=="button"){
            //If the focused component is a button, click the button.
            focusedComponent.click();
        }else{
            //Press the tab key programatically
            $.emulateTab();
            verifyOneMenu(campoFocado);
        }
    }
}

此功能在主体的onkeydown事件上执行. 这样做的目的是用Tab键代替回车键的默认行为. 唯一的问题是,当焦点所在的组件是selectOneMenu且用户按下Enter键时,它的行为就像Tab键一样,但是先前焦点所在的selectOneMenu被打开了(因为这是组件的默认行为).

This function is executed on the body's onkeydown event. The goal of this is to replace the default behavior of the enter key by the tab key. The only problem of this is, when the focused component is a selectOneMenu and the user hits enter, it correctly behaves like the tab key, but the selectOneMenu previously focused is opened(because this is the default behavior of the component).

所以,我想做的是调用以前关注的组件的selectOneMenu小部件var的close()方法.

So, what i am trying to do, is to call the close() method of the selectOneMenu widget var of that previously focused component.

推荐答案

您可以使用以下便捷功能通过id获取widgetVar对象:

You can get the widgetVar object by id using this handy function:

功能

function getWidgetVarById(id) {
   for (var propertyName in PrimeFaces.widgets) {
     if (PrimeFaces.widgets[propertyName].id === id) {
       return PrimeFaces.widgets[propertyName];
     }
   }
}

用法

getWidgetVarById('myFormName:myComponent');

示例

getWidgetVarById('dialogId').show();

查看更多:

  • Get widgetVar by Id
  • Intro To PrimeFaces widgetVar

这篇关于如何找到一个widgetVar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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