0

I posted a question previously See Here and nearly have a solution that I would like to post.

I have managed to get this working by using the following:

$(".todoList").sortable({
    update: function (event, ui) {
        if (this === ui.item.parent()[0]) {
            var numLists = $("ul.menu").length;
            for (var i = 1; i <= numLists; i++) {
                $.post("updateDB.php", {
                    pages: $("#menu-pages" + i).sortable('toArray'),
                    listid: i
                });
            }
        }
    },
    connectWith: ".connectedSortable"
});

However, with this solution it will query the DB x amount of times if I have x amount of lists. Before I post the answer, I want to know if it would be possible to create a 2D array of the arrays for each 'i' and only $.post once.

Thanks in advance.

4

1 回答 1

1

如果我理解你,你可以尝试这样的事情:

$(".todoList").sortable({
    update: function (event, ui) {
        if (this === ui.item.parent()[0]) {
            var numLists = $("ul.menu").length;
            var pages = [];
            for (var i = 1; i <= numLists; i++) {
                //here is the edit
                pages.push($("#menu-pages" + i).sortable('toArray'));
            }
            $.post("updateDB.php", {
                pages: pages
            });
        }
    },
    connectWith: ".connectedSortable"
});

现在您需要更改您updateDB.php的参数,因为通过此版本的代码传递的参数与以前不同。

于 2013-09-15T04:50:22.397 回答