四、代码实例
var gridster = [];
layout.map(function(item){
var div = $('<div class="app-column"></div>');
div.append('<div class="app-contents"><ul class="gridster"></ul></div>');
var widgetBaseDimensions = ['auto', 60],
widgetMargins = [10, 10],
maxCols = 24;
var g = div.find('.app-contents>ul')gridster({
widget_base_dimensions : widgetBaseDimensions,
widget_cols:maxCols,
max_cols:maxCols,
resize:{
enabled:true
},
draggable:{
handle:'nothing'
}
}).data('gridster');
gridster.push(g);
var widgets = [];
if(item.grids){
item.grids.map(function(gi){
var el = '<li class="widget" data-widgetid="' + gi.widgetId + '"'></li>';
var widgetTemp = [];
widgetTemp.push(el);
gi.sezex ? widgetTemp.push(gi.sezex) : widgetTemp.push(1);
gi.sezey ? widgetTemp.push(gi.sezey) : widgetTemp.push(1);
if(gi.col && gi.row){
widgetTemp.push(gi.col);
widgetTemp.push(gi.row);
}
widgets.push(widgetTemp);
});
}
$.each(widgets, function(i, widget){
g.add_widget.apply(g, widget);
})
})
gridster.map(function(grid){
grid.recalculate_faux_grid();
})
其中layout是json格式的配置