我正在尝试使用按钮在selectOneListbox中动态设置所选项目。
xhtml
<p:selectOneListbox id="basic1" widgetVar='commmentWidget' styleClass="commentClass" value="#{decisionTreeBean.option1}" style=" font-size: 12px;background-color:white;width:17em; height:13em; border-style:solid !important;border-width:0.5px !important; border-color:grey !important;" >
<f:selectItems value="#{decisionTreeBean.commentType}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
jQuery
jQuery(".generateBtn").on("click",function(event){
name=PF('commmentWidget').selectItem($('.ui-selectonelistbox-item[data-label*="Other"]'));
console.log(name);
});
这不起作用。另外,我的widgetVar上没有val()方法。
答案 0 :(得分:0)
PrimeFaces p:selectOneListbox
在选项/项目上没有设置任何属性,因此可以在'jquery'选择器中使用。因此,列表中的“索引”最常用于此组件
PF('commmentWidget').selectItem(PF('commmentWidget').jq.find("ul.ui-selectlistbox-list li:eq(4)"));
在这里,我使用li:eq(4)
从列表中选择第4个元素。