首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GridStack -重新初始化现有网格

GridStack -重新初始化现有网格
EN

Stack Overflow用户
提问于 2019-08-15 03:49:05
回答 1查看 363关注 0票数 1

我有一个元素,它已经针对它初始化了网格堆栈。

我希望保存并重新加载页面,并且希望在加载页面时网格可用。因此,当我加载页面时,我想重新初始化gridstack元素。

问题是它只是在元素及其子元素中添加了重复的类。

代码语言:javascript
复制
<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>

另外,我在根元素中添加了多个类:

代码语言:javascript
复制
class="grid-stack grid-stack-instance-4036 grid-stack-instance-4052"

那么,重新初始化网格的最佳方法是什么呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-15 20:40:50

下面是我对这个问题的解决方案:

代码语言:javascript
复制
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();
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57501128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档