我现在可以将项目拖动到可排序的项目。但是可排序列表具有不同的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)放入可排序的。
我希望我有意义。谢谢!
另一种说法: 当我拖着一个苹果时,它现在变成了橙色。但当我放下它时,它会变回苹果......
答案 0 :(得分:12)
$('.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))
}
});