【问题标题】:How to get the order of a sortable list made with sortablejs?如何获得用 sortablejs 制作的可排序列表的顺序?
【发布时间】:2020-08-11 08:59:31
【问题描述】:

我的代码如下所示:

new Sortable(sortablelist, {
                    animation: 150,
                    ghostClass: 'sortable-ghost'
                });
.box {
        background-color: powderblue;
        margin: 4px;
        padding: 2px;
        width: 25%;
        cursor: move;
    }
<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
    <script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"></script>
    </head>

    <body>
    <center>
  
        <div id="sortablelist">
            <div class="box" id="Item 1">Item 1</div>
            <div class="box" id="Item 2">Item 2</div>
            <div class="box" id="Item 3">Item 3</div>
        </div>
    
    </center>
    </body>
</html>

我是初学者,希望你能帮助我。我觉得我已经搜索了洞网。 订单将继续保存在数据库中,但我现在对 PHP 有点经验,并且认为我可以管理这个。

【问题讨论】:

标签: javascript drag-and-drop sortablejs


【解决方案1】:

如果你使用 JQuery,你可以使用sortable.toArray()

$("#sortablelist").sortable.toArray("orderedIds");

这会将可排序的所有项目的 ID 放入一个数组中。所以在你的情况下它会返回(如果你没有改变顺序):

["Item 1", "Item 2", "Item 3"]

【讨论】:

    猜你喜欢
    • 2020-04-18
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 2020-06-26
    • 2020-03-30
    相关资源
    最近更新 更多