How do you perform a reset on a JQuery Sortable

前端 未结 4 1481
我在风中等你
我在风中等你 2021-02-05 22:23

I\'m using JQuery Sortable. I\'d like to know if it\'s possible to, after a number of resortings, restore the sortable control back to its original state similar to a form reset

4条回答
  •  春和景丽
    2021-02-05 22:46

    You can cache a copy of the parent on document ready and restore it on reset.

    For example, if

      is your sortable element:

      var sortableCache;
      $(document).ready(function() {
          ...
          $('ul.parent').sortable({ ... });
          ...
          sortableCache = $('ul.parent').clone(true);
      });
      

      On reset, you can do:

      $('ul.parent').replaceWith(sortableCache);
      

提交回复
热议问题