我有两份名单
<ul class="sortable" id="list-A">
<li id="1">Value 1 </li>
<li id="2">Value 2 </li>
<li id="3">Value 3 </li>
</ul>
<ul class="sortable" id="list-B">
<li id="4">Value 1 </li>
<li id="5">Value 2 </li>
<li id="6">Value 3 </li>
</ul>像这样连接起来
$( ".sortable" ).sortable({
connectWith: '.sortable',
placeholder: "widget-highlight"
});我知道如何通过保存订单将一个有序列表保存到数据库,但是如果用户将一个项目从列表a移动到列表b,如何保存??
我想保存物品的位置,但是如何保存
发布于 2012-11-23 02:11:11
使用.sortable()的.receive()回调,通过ui.item.index()获取被丢弃节点的.index(),如何在ui.item.index()中处理它将取决于如何设置ajax处理程序。
$( ".sortable" ).sortable({
connectWith: '.sortable',
placeholder: "widget-highlight",
// Receive callback
receive: function(event, ui) {
// The position where the new item was dropped
var newIndex = ui.item.index();
// Do some ajax action...
$.post('someurl.php', {newPosition: newIndex}, function(returnVal) {
// Stuff to do on AJAX post success
});
},
// Likewise, use the .remove event to *delete* the item from its origin list
remove: function(event, ui) {
var oldIndex = ui.item.index();
$.post('someurl.php', {deletedPosition: oldIndex}, function(returnVal) {
// Stuff to do on AJAX post success
});
}
});上面的示例将发送删除节点在$_POST['newPosition']中的新列表位置
事件在 API documentation中完全描述。
https://stackoverflow.com/questions/13522216
复制相似问题