尝试创建一个复选框来检查树节点中的所有项目。我对 JSF 有点陌生,所以我很困惑如何在树而不是表上实现它。这是当前代码:
<rich:panel style="width:400px;">
<h:selectBooleanCheckbox id="vehicleAll" onclick="selectAllModel(this.checked);">
</h:selectBooleanCheckbox>
<h:outputText value=" ALL"/>
<rich:tree id="vehicleTree" switchType="client"
value="#{applicationScope.demoModelGrpList}" var="node" ajaxKeys="#{null}"
binding="#{demoRptController.vehicleUiTree}"
nodeSelectListener="#{demoRptController.selectionListener}"
changeExpandListener="#{demoRptController.expansionListener}"
ajaxSubmitSelection="true">
<rich:treeNode id="modelNode" ajaxSingle="true"
icon="/images/pixel_node.gif" iconLeaf="/images/pixel_node.gif">
<h:selectBooleanCheckbox id="cbxNode" value="#{node.selected}" style="position:relative; float:left; left:-22px;" class="vcBx">
</h:selectBooleanCheckbox>
<h:outputText value="#{node.name}" style="position:relative; float:left; left:-16px;"/>
</rich:treeNode>
</rich:tree>
</rich:panel>
脚本是:
<script type="text/javascript">
<![CDATA[
function selectAllModel(checks) {
alert("calling select all");
var array = document.getElementsByTagName("input");
for(var i = 0; i < array.length; i++)
{
if(array[i].type == "checkbox")
{
if(array[i].className == "vcBx")
{
array[i].checked = checks;
}
}
}
}
]]>
</script>
我将警报放在那里以进行测试;它甚至没有被调用。我很确定我的语法是正确的,所以这让我摸不着头脑。