javascript - 如何在创建新网格之前销毁网格堆栈?

标签 javascript jquery backbone.js

我使用单页应用程序,我在 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);
    }

模板:div class='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);
    }
})

布局设置.js

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

最佳答案

尝试

this.gridStack.removeAll();

destroy()

查看文档 here

关于javascript - 如何在创建新网格之前销毁网格堆栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29359353/

相关文章:

backbone.js - 如何避免 Backbone.js 中类似 View 的模板中的重复代码和逻辑

javascript - jQuery 中的条件语句

javascript - 如何上传到 javascript 字符串,绕过服务器?

javascript - 如何使用 href 提交表单并将隐藏值发送到 Controller

javascript - 下拉菜单落后于 'content' div

javascript - 删除整个数据库而不是一行

javascript - 无法使用 Backbone.js 将数据保存到 localStorage

javascript - AJAX 调用后未找到 404

javascript - 仅从 Google API 加载特定字体

javascript - Backbone Model 有条件地触发事件,View 听不到它