Jquery sortable('serialize')

前端 未结 6 1595
遥遥无期
遥遥无期 2021-02-01 08:57

Is it possible to get the serialized list of items from a UL in jquery by calling the serialize method directly instead of using a callback? The code snippet:

va         


        
6条回答
  •  渐次进展
    2021-02-01 09:39

    HTML

    • Item 1
    • Item 2
    • Item 3
    • Item 4
    • Item 5
    a

      JQuery

      $(document).ready(function () {
      
                  var updateOutput = function (e) {
                      var list = e.length ? e : $(e.target),
                          output = list.data('output');
      
                      if (window.JSON) {
                          output.val(window.JSON.stringify(list.sortable('serialize'))); //, null, 2));
                      } else {
                          output.val('JSON browser support required for this demo.');
                      }
                  };
      
                  $("#sortable1, #sortable2").sortable({
                      connectWith: ".connectedSortable",
                      update: function () {
                          updateOutput($('#sortable2').data('output', $('#json-output')));
                      },
                  }).disableSelection();
      
              });
      

      Result

      "item[]=1&item[]=4&item[]=2"
      

      Hope this help!

    提交回复
    热议问题