jQuery: What to do with the list that sortable('serialize') returns?

前端 未结 8 1468
我寻月下人不归
我寻月下人不归 2020-12-23 20:01

With jQuery I\'m retrieving positions of a sortable list using \'serialize\', like this:

var order = $(\'ul\').sortable(\'serialize\');

The vari

相关标签:
8条回答
  • 2020-12-23 20:33

    Solution

    I have created my own solution by manipulating sortable('serialize'). I have simplified it by using jquery functions, and then posted it to php url for updating order of list in the database. Have a look at my code.

    $( "#covercast_sortable" ).sortable({
            update : function () { 
                var order = $('#covercast_sortable').sortable('serialize',{key:'string'}); 
                // order var gives something like string=3&string=2&string=1
                var ar = order.split('&');
                var i = 0;
                var str = '';
                for(i;i<ar.length;i++){
                    if(str != "") { str += ','; }
                    // slice is used to remove 'sting=' from every value of var ar
                    str += ar[i].slice(7);
                }
                // here value of str is 3,2,1 with respect to order variable
                $.ajax({
                    type: "POST",
                    url: 'myURL.php',
                    data: 'order=' + str,
                    cache: false,
                    success: function (data) {
                        console.log(data);
                    }
                });
            }
        });
    

    Cheers

    0 讨论(0)
  • 2020-12-23 20:34
    var order = $('#projects ul').sortable('toArray'});
    

    this might work too ;)

    0 讨论(0)
提交回复
热议问题