首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery可排序地将connectWith列表保存到mysql数据库php

jquery可排序地将connectWith列表保存到mysql数据库php
EN

Stack Overflow用户
提问于 2012-11-23 01:47:58
回答 1查看 3.4K关注 0票数 2

我有两份名单

代码语言:javascript
复制
<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>

像这样连接起来

代码语言:javascript
复制
     $( ".sortable" ).sortable({
       connectWith: '.sortable',
       placeholder: "widget-highlight"
     });

我知道如何通过保存订单将一个有序列表保存到数据库,但是如果用户将一个项目从列表a移动到列表b,如何保存?

我想保存物品的位置,但是如何保存

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-23 02:11:11

使用.sortable().receive()回调,通过ui.item.index()获取被丢弃节点的.index(),如何在ui.item.index()中处理它将取决于如何设置ajax处理程序。

代码语言:javascript
复制
$( ".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中完全描述。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13522216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档