Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可拖动的连接到可排序的_Javascript_Jquery_Jquery Ui_Jquery Ui Draggable_Jquery Ui Sortable - Fatal编程技术网

Javascript 可拖动的连接到可排序的

Javascript 可拖动的连接到可排序的,javascript,jquery,jquery-ui,jquery-ui-draggable,jquery-ui-sortable,Javascript,Jquery,Jquery Ui,Jquery Ui Draggable,Jquery Ui Sortable,我希望能够将项目从一个Infrastics数据网格拖到另一个,同时目标网格中的项目也可以排序 不幸的是,我不能使用JSFIDLE,因为我不能使用那里的infragistics控件 $("[id*=sourceGrid] [id*=dataTbl] tbody tr").draggable({ helper: "clone", revert: "invalid", connectToSortable: '[id*=destination]'

我希望能够将项目从一个Infrastics数据网格拖到另一个,同时目标网格中的项目也可以排序

不幸的是,我不能使用JSFIDLE,因为我不能使用那里的infragistics控件

$("[id*=sourceGrid] [id*=dataTbl] tbody tr").draggable({
   helper: "clone",
   revert: "invalid",
   connectToSortable: '[id*=destination]'                   
});

$("[id*=destinationGrid]").sortable({
   cursor: 'move',
   helper: fixHelperModified,    
   revert: true,
   items: "[id*=container] [id*=dataTbl] tbody tr:not(.placeholder)",                
   receive: function (event, ui) {                    
      var grid = $IG.WebDataGrid.find("destinationGrid");                   
      $sentence = $(ui.item).find("td").eq(0).html();
      var row = new Array(Math.floor((Math.random() * 100) + 1), $sentence, $order);
      grid.get_rows().add(row);                  
  }
});

问题是:当我将项目从sourceGrid拖放到destinationGrid时,我不想将Dragable放到新的网格中——我只想使用receive函数在网格中使用Dragable元素的值创建新行。现在,我同时得到了新创建的gridRow和删除的项。如何防止这种情况发生?

您可以在beforeStop事件中捕获复制的项目

var newItem;

$(".list").sortable({
  connectWith: ".list",
  beforeStop: function (event, ui) { 
      newItem = ui.item;
  },
  receive: function(event,ui) {
      $(newItem).doSomething();
  }
});​

此答案的参考和认可:

您尝试过什么?如何将“helper”方法更改为原始方法,然后在拖放时删除()?抱歉,忘了提及。我需要“克隆人”的行为。我不想移动,但将项目从源克隆到目标,并且仍保留在源中。当我
remove()
接收事件中的ui.item时,我会删除sourceGrid中的原始行。这种行为非常奇怪,我不明白为什么ui.item是我拖动的原始元素,而不是克隆的占位符。您是否也尝试过将
sourceGrid
设置为可排序的()?另外,在
receive
事件中,您可以console.log ui.helper吗?