我现在可以拖动一个项目到一个可排序.但是可排序列表具有不同的DOM.
<!-- The draggable items. Has the "original" DOM in the LI tags. --> <ul class="draggable_text"> <li><span>DRAG THIS A</span></li> <li><span>DRAG THIS B</span></li> </ul> <!-- This list has a different DOM in the LI tags --> <ul id="stagerows"> <li><p>This is a new DOM dragged from "DRAG THIS A"</p></li> <li><p>This is a new DOM dragged from "DRAG THIS B"</p></li> </ul> $(document).ready(function() { $('.draggable_text > li').draggable({ //helper:'clone',helper: function(event,ui) { return '<div style="width: 100px; height: 50px; border: 1px solid #000; background-color: #fff;">xxx</div>'; },connectToSortable:'#stagerows' }); $('#stagerows').sortable({ handle: '.drag_handle' }); });
助手有这个:
XXX
这应该放在可排序的…
“助手”的作品.但是当我将项目“放弃”到可排序中时,它只会恢复到“原始”DOM.我想要将“新创建的DOM”(在帮助器中创建的DOM)放入可排序.
我希望我有意义谢谢!
另一种说法:
当我拖一个苹果,现在变成一个橙色.但是当我放弃它,它变成一个苹果..
解决方法
$('.draggable_text > li').draggable({ helper: function(event,ui) { var type = $(this).find('.link_type').val(); return create(type,0); },connectToSortable:'#stagerows' }); $('#stagerows').sortable({ handle: '.drag_handle',placeholder: 'placeholder_sortable' }); /** * When item is dropped from the Add <Stuff> */ $('#stagerows').droppable({ drop: function(event,ui){ type = ui.draggable.find('.link_type').val(); ui.draggable.empty(); return ui.draggable.html(create(type,0)) } });