Not getting gridster serialize data after resizing the boxes

耗尽温柔 提交于 2019-12-07 12:21:01

问题


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);
                 });


来源:https://stackoverflow.com/questions/25637365/not-getting-gridster-serialize-data-after-resizing-the-boxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!