如何在创建新的之前销毁 gridstack?

How to destroy gridstack before create new?

我使用单页应用程序,我在 3 个页面中创建了 3 个 Gridstack。
如果我一页一页打开,每页调整小部件的速度都会变慢。
但是,如果我重新加载页面,它就可以正常工作。

我使用 Backbone 的路由器打开每个页面(不是重新加载页面)。
这是我的代码:
网格-satck.js

createGridStack: function(gridEl) {
        var options= {
            animate: true,
            width: 12,
            cell_height: 50,
            resizable: {
                handles: "e, se, s, sw, w"
            }
        };
        $(gridEl).gridstack(options);
    }

模板:divclass='grid-stack'/>

HomePageLayout.js

return Backbone.Marionette.LayoutView.extend({
    template: "template",
    onShow: function() {
       createGridStack($(".grid-stack"));
       this.gridStack = $(gridStackEl).data('gridstack');
       this.gridStack.movable('.grid-stack-item', false);
       this.gridStack.resizable('.grid-stack-item', false);
    }
})

ClientLayout.js

return Backbone.Marionette.LayoutView.extend({
    template: template,
    onShow: function() {
       createGridStack($(".grid-stack"));
       this.gridStack = $(gridStackEl).data('gridstack');
       this.gridStack.movable('.grid-stack-item', false);
       this.gridStack.resizable('.grid-stack-item', false);
    }
})

LayoutSetting.js

return Backbone.Marionette.LayoutView.extend({
    template: "template",
    onShow: function() {
       createGridStack($(".grid-stack"));
       this.gridStack = $(gridStackEl).data('gridstack');
    }
})

尝试

this.gridStack.removeAll();

destroy()

查看文档 here