gpt4 book ai didi

jqgrid - 销毁 jqGrid 以避免分离的 DOM 节点的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-01 06:50:36 27 4
gpt4 key购买 nike

我目前面临的情况是,在创建一组新的 DOM 元素之前,我需要销毁一个包含大量行的 jqGrid。我试过使用 jqGrid 的 GridDestroy 方法,但它仍然留下大量分离的 DOM 节点,所以我想我可能做错了。

这是我当前的进程,它仍然离开分离的 DOM 节点:

$(deleteButton).click(function () {
$('#grid').jqGrid("clearGridData");
$('#grid').jqGrid('GridDestroy');
$('#grid').remove();
$('#gridContainer').empty();
});

我觉得这个过程有点矫枉过正,但它仍然导致 DOM 节点分离。我已经在 jsFiddle ( http://jsfiddle.net/8DYD8/1/ ) 中设置了一个示例。

重现步骤:
  • 单击创建按钮创建 jqGrid
  • 点击删除按钮
  • 使用 Chrome 的 debugger->Profiles 选项卡拍摄堆快照,您应该会在快照中看到许多分离的 DOM 节点

  • Detached DOM nodes due to jqGrid

    最佳答案

    根据 jqgrid 专家@oleg 的说法:

    The method GridDestroy works like jQuery.remove. It deletes all elements which belong to the grid inclusve the element.

    The method GridUnload on the other hand delete all, but the empty element stay on the page. So you are able to create new grid on the same place.



    根据 jqGrid 维基:

    http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

    GridDestroy 是你需要的:

    Destroys the entry grid with id= grid_id from the DOM (clears all the html associated with the grid and unbinds all events)

    关于jqgrid - 销毁 jqGrid 以避免分离的 DOM 节点的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22021026/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com