Jquery可排序更新事件只能调用一次?
我正在尝试使用Jquery&Php进行类别更改。 我没问题。 我的问题是,当调用update事件时,它返回2个结果。 拖动父项的1个结果,Dropped Parent的一个结果。 我想只打电话给父母的身份。 这是我的脚本:
$("#gallery ul").sortable({ connectWith: '.dropBox', opacity: 0.35, scroll: true, scrollSensitivity: 100, //handle: '.move', helper: 'clone', containment:'#gallery', accept:'#gallery > .photo', revert: true, update: function(event, ui){ params = 'c=' + $(this).attr('id') + '&id=' + ui.item.attr('id'); $.ajax({ type: 'POST', url: 'processData.php', data: params, error:function(){ alert("Error!"); }, success:function(data){ $("#serverResponse").html(data); } }); } }).disableSelection();
你能帮帮我们吗?
例如,使用update
, stop
和receive
事件
$(function() { position_updated = false; //flag bit $(".sortable").sortable({ connectWith: ".sortable", update: function(event, ui) { position_updated = !ui.sender; //if no sender, set sortWithin flag to true }, stop: function(event, ui) { if (position_updated) { //code position_updated = false; } }, receive: function(event, ui) { // code } }).disableSelection(); });
ui.sender
仅存在于第二个回调中。
$(".sortable").sortable({ connectWith: ".sortable", update: function (evt, ui) { // just ignore the second callback if(ui.sender == null){ // call ajax here } }, receive: function (evt, ui) { // called after the first 'update' // and before the second 'update' // ui.sender is always exists here } }).disableSelection();
您应该尝试使用sortable
不同事件
- 开始
- 分类
- 更改
- beforeStop
- 停
- 更新
- 接收
- 去掉
- 过度
- 出
- 启用
- 关闭
我很确定其中一个会是你的答案。
资料来源: http : //jqueryui.com/demos/sortable/#event-change
这样做:
update: function(event, ui) { if(ui.sender) { // Your actual code } },