Skip to content

.destroy(false) doesn't remove the data object #422

Closed

Description

@Tuizi

Hello,

The destroy method with parameter false, doesn't remove the "data" object attach to the DOM.
Here is a example:

 $('.grid-stack').gridstack(options);

var gridStack = $('.grid-stack').data("gridstack");

console.debug(gridStack); // { Object }

gridStack.destroy(false);

var gridStack = $('.grid-stack').data("gridstack");

console.debug(gridStack); // { Object } **!!!!**

The problem with that if when, then, on the same DOM element I do:

$('.grid-stack').gridstack(options); //Will do nothing!

This code do nothing because the first thing you do is:

$.fn.gridstack = function(opts) {
    return this.each(function() {
        var o = $(this);
        if (!o.data('gridstack')) { // <= this will never be true, because destroy doesn't have removed this data object
            o
                .data('gridstack', new GridStack(this, opts));
        }
    });
};

Activity

  1. Tuizi commented on Apr 13, 2016

    @Tuizi
    Author

    A workaround is to do:

    $('.grid-stack').gridstack(options);
    var gridStack = $('.grid-stack').data("gridstack");
    
    gridStack.destroy(false);
    gridStack.container.removeData("gridstack");
    
    $('.grid-stack').gridstack(options); //Now, this works as expected
  2. added a commit that references this issue on Aug 17, 2016
    ceef60d
  3. added this to the v0.2.7 milestone on Aug 17, 2016
  4. radiolips commented on Aug 17, 2016

    @radiolips
    Member

    @Tuizi Apologies for the delay, but I believe you will no longer need to use your workaround. Thanks for your patience, and let us know if you're having any continued issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions