我有一个元素,它已经针对它初始化了网格堆栈。
我希望保存并重新加载页面,并且希望在加载页面时网格可用。因此,当我加载页面时,我想重新初始化gridstack元素。
问题是它只是在元素及其子元素中添加了重复的类。
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90; display: none;"></div>
<div class="ui-resizable-handle ui-resizable-sw" style="z-index: 90; display: none;"></div>另外,我在根元素中添加了多个类:
class="grid-stack grid-stack-instance-4036 grid-stack-instance-4052"那么,重新初始化网格的最佳方法是什么呢?
发布于 2019-08-15 20:40:50
下面是我对这个问题的解决方案:
var stacks = $(".grid-stack");
stacks.each(function () {
var grid = $(this).data("gridstack");
if (typeof grid !== "undefined") {
grid.destroy(false);
}
//use regex to remove the multiple classnames
$(this).removeClass(function (index, className) {
return (className.match(/(^|\s)grid-stack-instance-\S+/g) || []).join(" ");
});
$(this).find(".ui-resizable-handle").remove();
});https://stackoverflow.com/questions/57501128
复制相似问题