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

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

问题描述

我的手风琴在页面加载时工作正常,但是在用户与页面上的某些元素交互时,我使用 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 与页面加载的完全相同(除了 Accordion 方法有效时发生的 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)

推荐答案

在用数据重新填充之前销毁手风琴.

Destroy the accordian before repopulating it with data.

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

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

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