将订单保存在可排序的jquery关联列表中

时间:2018-07-19 13:58:48

标签: php jquery ajax jquery-ui-sortable

我的代码工作正常..但是我想在进行任何更改后立即将订单保存在第二列的Mysql中...我可以做的PHP编程,只是不知道如何将更改发送到php文件

查看我的代码(完整代码位于http://jsfiddle.net/helpinspireme/wMnsa/中)

        <ul id="unassigned_list" class="connected_sortable">
        <li class="ui-state-default"><div class="draggable_area">Item 1</div><div class="click_area">&#8594;</div><div class="cl"></div></li>
        <li class="ui-state-default"><div class="draggable_area">Item 2</div><div class="click_area">&#8594;</div><div class="cl"></div></li>
    </ul>
    <ul id="recipients_list" class="connected_sortable">
        <li class="ui-state-highlight"><div class="draggable_area">Item 3</div><div class="click_area">&#8592;</div><div class="cl"></div></li>
        <li class="ui-state-highlight"><div class="draggable_area">Item 4</div><div class="click_area">&#8592;</div><div class="cl"></div></li>
    </ul>
    <script>
$("#unassigned_list, #recipients_list").sortable({
    connectWith: ".connected_sortable",
    items: "li",
    handle: ".draggable_area",
    stop: function(event, ui) {
        updateLi(ui.item);
    }
}).disableSelection().on("click", ".click_area", function() {
    // First figure out which list the clicked element is NOT in...
    var otherUL = $("#unassigned_list, #recipients_list").not($(this).closest("ul"));
    var li = $(this).closest("li");

    // Move the li to the other list. prependTo() can also be used instead of appendTo().
    li.detach().appendTo(otherUL);

    // Finally, switch the class on the li, and change the arrow's direction.
    updateLi(li);
});

function updateLi(li) {
    var clickArea = li.find(".click_area");
    if (li.closest("ul").is("#recipients_list")) {
        li.removeClass("ui-state-default").addClass("ui-state-highlight");
        clickArea.html('&#8592;');
    } else {
        li.removeClass("ui-state-highlight").addClass("ui-state-default");
        clickArea.html('&#8594;');
    }    
}
</script>

1 个答案:

答案 0 :(得分:0)

您可以通过将id添加到元素并将下面的代码添加到sortable来实现:

update: function() {
    var order = $(this).sortable('toArray');
    alert(order);
  }

Online demo (jsFiddle)