在回调时重新初始化jquery手风琴 [英] re-initialize jquery accordion on callback

查看:125
本文介绍了在回调时重新初始化jquery手风琴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有手风琴在pageload上工作正常,但是当用户与页面上的一些元素交互时,我使用ajax重建手风琴的HTML。然后,我尝试用

I've got the accordion working fine on pageload, however upon user interaction with some elements on the page, I am using ajax to rebuild the HTML of the accordion. Then, I try to re-initialize the accordion again with

    $('#accordion').accordion({
        active: false,
        autoHeight: false,
        clearStyle: true,
        collapsible: true,
        header: 'h3'
    });

但它似乎没有带走。

新的HTML代码块不应用手风琴规则。

The new block of rendered HTML isn't applying the accordion rules. Instead it just stays open as a large list.

我甚至试过setTimeout()来重新调用手风琴,只是它试图在渲染的HTML之前初始化

I've even tried setTimeout() for re-calling the accordion just incase it was trying to initialize before the rendered HTML is returned in the callback.

在回调中呈现的HTML与pageload的HTML完全相同(除了手风琴出现的DOM添加外,方法有效)

The HTML that is rendered in the callback is the exact same as that of the pageload (with exception to the DOM additions that occur when the Accordion method is effective)

推荐答案

在用数据重新填充之前销毁accordian。

Destroy the accordian before repopulating it with data.

$('#accordion').accordion('destroy');

这篇关于在回调时重新初始化jquery手风琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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