我也非常头疼如何实现这一目标。我从 jQuery 帖子获取网格数据,该帖子返回 JSON 数据并构建 te 位置数组。在你的情况下,这可能是:
var seri_data = [];
this.serialized_data = seri_data;
jQuery.post( 'yourfile.php', function( data ) {
jQuery.each( data, function( key, value ) {
seri_data.push({
'id' : this.widgetId,
'x' : this.x,
'y' : this.y,
'width' : this.width,
'height' : this.height,
});
});
});
使用下面的代码,它是 gridstack 序列化演示示例的基础,可以找到here https://gridstackjs.com/demo/serialization.html。打开该页面的源代码并查看加载函数部分...使用下面提供的代码更改其代码。
_.each( items, function( node ) { this.grid.add_widget( jQuery( '<div data-gs-id="widget_' + node.id + '" class="grid-stack-item"><div class="grid-stack-item-content"></div></div>' ), node.x, node.y, node.width, node.height ); }, this );