質問

I tried to store all event handler of an element, then unbind them, then do something and then bind again, but aparently the variable with the handlers gets modified to an empty object when i unbind the handlers

  var events = $._data(this.$element.get(0), 'events');
  console.log(events);    //here the variable events contains an object with the handlers
  this.$element.unbind();
  console.log(events);   //here the variable events contains an empty object

  //function to bind again the handlers
  $.each(events, function() {
    // iterate registered handler of original
    $.each(this, function() {
      $('#target').bind(this.type, this.handler);
    });
  });
役に立ちましたか?

解決

You can use extend in deep mode to copy data in events:

var events = $._data(this.$element.get(0), 'events'),
    eventsCopy = $.extend(true, {}, events);
this.$element.unbind();
$.each(eventsCopy, function() {
    $.each(this, function() {
        $('#target').bind(this.type, this.handler);
    });
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top