Skip to content Skip to sidebar Skip to footer

Jquery Sortable Updated Data Not Being Serialized

I am using the jQuery Sortable plugin. Looking at the basic example on how to serialize the data I have the below code.
    Copy
  1. https://github.com/jquery/jquery/blob/1.9-stable/src/data.js#L244

    if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
    
  2. https://github.com/jquery/jquery/blob/1.9-stable/src/data.js#L252

    dataAttr( elem, name, data[ name ] );
    
  3. https://github.com/jquery/jquery/blob/1.9-stable/src/data.js#L291

    if ( data === undefined && elem.nodeType === 1 ) {

So the reason is that the data is cached by jQuery.

The solution:

var group = $("ol.serialization").sortable({
    group: 'serialization',
    delay: 500,
    onDrop: function (item, container, _super) {
        group.children().each(function(){
            jQuery._data(this, 'parsedAttrs', false);
            jQuery.removeData(this);
        });
        var data = group.sortable("serialize").get();
        var jsonString = JSON.stringify(data, null, ' ');
        console.log(jsonString);
        $('#serialize_output2').text(jsonString);
        _super(item, container)
     }
 })

This fiddle: http://jsfiddle.net/hb6hU/1/

Post a Comment for "Jquery Sortable Updated Data Not Being Serialized"