using jQueryUI sortable list with forms

前端 未结 2 2214
萌比男神i
萌比男神i 2021-02-19 04:10

I\'m using jQueryUI to create a sortable list, and the UI part works great in that I can sort the items as desired on the web page. I can\'t figure out, though, how the order o

2条回答
  •  被撕碎了的回忆
    2021-02-19 04:44

    Another option is to just have a hidden input form field with the ID value for the item as the value and the same name. Then submit the form after sorting stops. The values will all be available in the posted data in the order they were after the sort.

    I do something like this:

    $(".sortable").each(function () {
        $(this).sortable({
            update: function (event, ui) {
                $(this).closest("form").trigger("onsubmit");
            }
        });
    });
    

    And the form looks like this:

    • Some info here
    • Some more info

提交回复
热议问题