如何获得使用sortablejs进行排序的可排序列表的顺序?

问题描述

我的代码与此类似:

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有一点经验,并且认为我可以管理它。

解决方法

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

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

这会将可排序的所有项目的ID放入数组。因此,在您的情况下,它将返回(如果您尚未更改订单):

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...