Cloned Select2 is not responding

前端 未结 13 2427
长发绾君心
长发绾君心 2020-11-29 03:51

I am trying to clone a row which contains select2 tool ,when i clone that row using jQuery the cloned select2 is not responding.In image given below first select2 which is o

13条回答
  •  盖世英雄少女心
    2020-11-29 04:38

    I solved this by creating a different clone function:

    jQuery.fn.cloneSelect2 = function (withDataAndEvents, deepWithDataAndEvents) {
      var $oldSelects2 = this.is('select') ? this : this.find('select');
      $oldSelects2.select2('destroy');
      var $clonedEl = this.clone(withDataAndEvents, deepWithDataAndEvents);
      $oldSelects2.select2();
      $clonedEl.is('select') ? $clonedEl.select2() :
                                $clonedEl.find('select').select2();
      return $clonedEl;
    };
    

提交回复
热议问题