How do you perform a reset on a JQuery Sortable

前端 未结 4 1380
我在风中等你
我在风中等你 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:49

    I personally like doing it this way:

    $("#sortable").sortable({config...});
    var cache = $("#sortable").html();
    

    On Reset

    $("#sortable").html(cache).sortable("refresh");
    

    I tried using .clone() and.children() and even $("#sortable > *), but find caching the .html() the best option.

    In my situation, I have two connected lists. One containing current items the user can sort or remove and another list of available items that the user can grab from to add to the "current item" list. I needed a way to reset everything to original state. The above works great.

提交回复
热议问题