简体   繁体   English

使用f:ajax(JSF)更新后,为什么我的Materialize可折叠菜单不起作用?

[英]Why is it that my Materialize collapsible menu doesn't work after updating with f:ajax (JSF)?

I am working with JSF 2.2 and Materialize. 我正在使用JSF 2.2和Materialize。 I need to update a collapsible dynamic list when the user sends one basic form with h:form , h:commandButton and f:ajax labels. 当用户使用h:formh:commandButtonf:ajax标签发送一种基本形式时,我需要更新可折叠的动态列表。

This is the code for the form sent by the user: 这是用户发送的表单代码:

<h:form>
    ...
    <h:commandButton value="send!" action="#{...}">
        <f:ajax render="@form pgMenu" execute="@form"/>
    </h:commandButton>
</h:form>

And this code represents the menu to be updated: 此代码表示要更新的菜单:

<h:panelGroup id="pgMenu">
    <ul class="collapsible myList">
        <h:panelGroup rendered="#{not empty bean.variable}">
            <li class="bold item-li"><a class="collapsible-header item-a">New</a>
                <div class="collapsible-body">
                    <ul>
                        <a href="page1.xhtml"><li class="li-izquierda">New 1</li></a>
                        <a href="page2.xhtml"><li class="li-izquierda">New 2</li></a>
                    </ul>
                </div>
            </li>
        </h:panelGroup>
        <li class="bold item-li"><a class="collapsible-header item-a">Fases</a>
            <div class="collapsible-body">
                <ul>
                    <a href="#"><li class="li-izquierda">Planeación</li></a>
                    <a href="#"><li class="li-izquierda">Otra mas</li></a>
                </ul>
            </div>
        </li>
        <li class="bold item-li"><a class="collapsible-header item-a waves-teal">JavaScript</a>
            <div class="collapsible-body">
                <ul>
                    <a href="#"><li class="li-izquierda">Collapsible</li></a>
                    <a href="#"><li class="li-izquierda">Dialogs</li></a>
                </ul>
            </div>
        </li>
    </ul>
</h:panelGroup>

My problem is that when pgMenu is updated, the menu js behavior freezes. 我的问题是,更新pgMenu时,菜单js行为冻结。

The next images show the menu before and after sending the form (I am clicking options). 下图显示了发送表单前后的菜单(我正在单击选项)。

Before update 更新之前

在此处输入图片说明

After update 更新后

在此处输入图片说明

Thank you! 谢谢!

After each update, your DOM structure is changing, therefore you need to destroy previous instance of Collapsible class: 每次更新之后,您的DOM结构都会发生变化,因此您需要销毁Collapsible类的先前实例:

instance.destroy();

And then, after your new structure is rendered, you need to reinitialize Collapsible: 然后,在呈现新结构之后,您需要重新初始化Collapsible:

var newElement = document.getElementById('YOUR_COLLAPSIBLE_CONTAINER');
var instance = new M.Collapsible(newElement, {YOUR OPTIONS});

I'm afraid that is your only option, when using materialize-css library. 使用materialize-css库时,恐怕这是您唯一的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM