Not getting gridster serialize data after resizing

2019-05-11 05:00发布

问题:

I am trying to get serialized data after changing the size and position of boxes. But I get the on load details only. How to get serialize data after resize the boxes. And I also want to get the text(value in the box) of the box.

This is my code:

  $(function() {

  var gridster = $(".gridster > ul").gridster({
      widget_margins: [10, 10],
      widget_base_dimensions: [230, 160],
      helper: 'clone',
      resize: {
          enabled: true,

      },
      serialize_params: function($w, wgd) {
          return {
              id: $($w).attr('.drop'),
              col: wgd.col,
              row: wgd.row,
              size_x: wgd.size_x,
              size_y: wgd.size_y
          };
      }

  }).data('gridster');

  //serialization//

  var gridster = $(".gridster > ul").gridster().data('gridster');
  gridData = gridster.serialize();
  /*alert(gridData.toSource())*/

  $('.js-seralize').on('click', function() {
      alert(gridData.toSource());
  });

  //delete//

  $(".del_img").click(function() {
      gridster.remove_widget($(this).parent());
  });
});

Please check this link

Please Help.

Thanks in advance.

//tried some thing like this also //

var finalserializer="[";
$(.re_boxes).each(function(){
var xaxisval = $(this).attr("data-sizex");
var yaxisval = $(this).attr("data-sizey");
var colval = $(this).attr("data-col");
var rowval = $(this).attr("data-row");
var coltitle = $(this).children("a").text();
var currentfinal = "{col:"+colval+"row:"+rowval+"xsize:"+xaxisval+"ysize:"+yaxisval+"coltitle:"+coltitle+"}"
finalserializer = finalserializer+currentfinal;
});
finalserializer=finalserializer+"]"
 });

$('.js-seralize').on('click', function() {
                    alert(gridData.toSource())
             });

回答1:

Try This:

 var gridster = $(".gridster > ul").gridster().data('gridster');
                     gridData = gridster.serialize();  
             $('.js-seralize').on('click', function() {
                   // alert(gridData.toSource())
                   var finalserializer="[";
                   $('.re_boxes').each(function(){
                    var xaxisval = $(this).attr("data-sizex");
                    var yaxisval = $(this).attr("data-sizey");
                    var colval = $(this).attr("data-col");
                    var rowval = $(this).attr("data-row");
                    var coltitle = $(this).find("a").text();
                    var currentfinal = "{'col':"+colval+",'row':"+rowval+",'size_x':"+xaxisval+",'size_y':"+yaxisval+",'text:'"+coltitle+"}";
                    finalserializer = finalserializer+currentfinal;
                   });
                   finalserializer=finalserializer+"]";
                   alert(finalserializer);
                 });