简体   繁体   English

结合使用sortable.js和html5自定义数据属性

[英]Using sortable.js with html5 custom data attribute

How does one use html5's custom data attribute to sort items using sortable.js. 如何使用html5的自定义数据属性通过sortable.js对项目进行排序。 Or how does one define custom sorting parameter using sortable.js 或者如何使用sortable.js定义自定义排序参数

For example in the code below, I'd like to sort with data-timestamp 例如,在下面的代码中,我想对数据时间戳进行排序

<ul id="items">
    <li data-timestamp='1'>item Y</li>
    <li data-timestamp='2'>item B</li>
    <li data-timestamp='3'>item Z</li>
</ul>

Using the store feature documented here: https://github.com/SortableJS/Sortable#store 使用此处记录的store功能: https : //github.com/SortableJS/Sortable#store

You can pass Sortable a sorted array of the attributes, and set the dataIdAttr to 'data-timestamp' 您可以传递dataIdAttr属性的排序数组,并将dataIdAttr设置为'data-timestamp'

Sortable.create(el, {
    dataIdAttr: 'data-timestamp',
    store: {
        get: function () {
            return ['1', '2', '3'];
        }
    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM