Sortable.js 插件 怎么保存排序后的顺序?
不是jquery ui里的.
<ul id="items">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
li都是动态生成的. 该怎么保存排序 和 输出新的排序?
自带属性里的这个属性怎么用? 怎么好像没效.
dataIdAttr: 'data-id',
怪我咯2017-04-11 10:11:52
请参考文档: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('|'));
}
}
})