0

我有多个从 MySQL 中的列表动态生成的可排序列表。每个列表的 id 使用数据库中的部分 id 附加。排序后,数据被序列化并发送到 sort_order_piece.php 以运行 MySQL 查询以更新记录的顺序,一切正常。不起作用的是我编写以下 jQuery 以说明每个列表的动态生成的 id 的方式:

$(".sortme_piece").each(
    function(e) {
        num = e+1;
        $('#sortme_piece_'+num).sortable({
            placeholder: "ui-state-highlight",
            update : function () {
                serial = $('#sortme_piece_'+num).sortable('serialize');
                alert(serial);
                $.ajax({
                    url: "sort_order_piece.php",
                    type: "post",
                    data: serial,
                    beforeSend: function(){$('#updated').html('updating');},
                    success: function(data){$('#updated').html(data);},
                    error: function(){alert("theres an error with AJAX");}

                });
            }
        });
    });

这条线似乎是麻烦:

serial = $('#sortme_piece_'+num).sortable('serialize');

当我在警告框中查看变量时,它是空白的。如果我删除附加的“数字”并添加一个与列表 ID 之一相对应的实际数字,它就可以正常工作。

我到底做错了什么?我只是无法确定它。

帮助和感谢!!!

4

1 回答 1

0

我变了

serial = $('#sortme_piece_'+num).sortable('serialize');

serial = $(this).sortable('serialize');

并修复了它。

于 2012-04-19T03:35:53.790 回答