Gridstack.js: 将位置导出为 json

创建于 2018-08-01  ·  3评论  ·  资料来源: gridstack/gridstack.js

@hairyheron
你好,
如何将当前位置导出为 JSON 格式,然后通过此 json 显示。

question

最有用的评论

如果你想在页面上保留 gridstack 的布局,这里有一个简短的例子:

var getGridJSON = function () {
    var nodes = $('#gridstack').data('gridstack').grid.nodes;
    return nodes.map(function(obj, idx){
       return {
           x: obj.x,
           y: obj.y,
           width: obj.width,
           height: obj.height,
           minHeight: obj.minHeight,
           minWidth: obj.minWidth
       }
    });
};
// this will give you array with each gridstack item, stringify it and persist in the backend :)
console.log(getGridJSON());

所有3条评论

我不是这个项目的维护者。 即使我是,我也不明白你的问题。

如果你想在页面上保留 gridstack 的布局,这里有一个简短的例子:

var getGridJSON = function () {
    var nodes = $('#gridstack').data('gridstack').grid.nodes;
    return nodes.map(function(obj, idx){
       return {
           x: obj.x,
           y: obj.y,
           width: obj.width,
           height: obj.height,
           minHeight: obj.minHeight,
           minWidth: obj.minWidth
       }
    });
};
// this will give you array with each gridstack item, stringify it and persist in the backend :)
console.log(getGridJSON());

谢谢, @zhanazhan 。 这看起来是一个很好的解决方案。

此页面是否有帮助?
0 / 5 - 0 等级