javascript - Sortable.js 插件 怎么保存排序后的顺序?
迷茫
迷茫 2017-04-11 10:09:52
0
1
536

Sortable.js 插件 怎么保存排序后的顺序?
不是jquery ui里的.

<ul id="items">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
</ul>

li都是动态生成的. 该怎么保存排序 和 输出新的排序?

自带属性里的这个属性怎么用? 怎么好像没效.
dataIdAttr: 'data-id',

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
刘奇

请参考文档:https://github.com/RubaXa/Sor...

<ul>
    <li data-id="1">order</li>
    <li data-id="2">save</li>
    <li data-id="3">restore</li>
</ul>
Sortable.create(el, {
    group: "localStorage-example",
    store: {
        /**
         * Get the order of elements. Called once during initialization.
         * @param   {Sortable}  sortable
         * @returns {Array}
         */
        get: function (sortable) {
            var order = localStorage.getItem(sortable.options.group.name);
            return order ? order.split('|') : [];
        },

        /**
         * Save the order of elements. Called onEnd (when the item is dropped).
         * @param {Sortable}  sortable
         */
        set: function (sortable) {
            // 这里是获取新的排序数组
            var order = sortable.toArray();
            localStorage.setItem(sortable.options.group.name, order.join('|'));
        }
    }
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!