所以你想要达到的可以这样概括
第1步:将一些布局(位于li标签内)从#list3拖放到#list2。
第 2 步:从
#list1 直接到#list2 和#list2 布局的ul 标签.drop-container 现在已经被拖到#list2 。
目前,您正在将#list1 li 放入#list 2,但它应该放入.drop-container of #list2 或#list2(如果您想直接将#list li 添加到#list2)
所以#list1 li 应该连接到.drop-container of #list2 和#list2
$("#list1 li").draggable({
connectToSortable: "#list2 .drop-container,#list2",//both element should be connected
helper: "clone",
revert: "invalid",
greedy: true
});
之后,sortable API 需要在 #list2 收到来自#list3 的一些 Layout 后才添加到 .drop-container of #list2
所以在list2 的sortable 的接收方法中调用sortable 上的#list2 .drop-container。
现在你#list2的接收函数变成了
receive: function (event, ui) {
console.log(ui);
console.log(event);
var this_id = $(ui.item).attr("id");
var preview = $(itemContext).html().replace(/<!--/g, '').replace(/-->/g, '');
$(itemContext).attr("id", this_id);
$(itemContext).css("width", $('#list2').width() - 20).addClass("ui-state-default").height('auto');
$(itemContext).html(preview);
//Modified code starts here, the sortable should be added here
$("#list2 .drop-container").sortable({//call sortable to every element which you want to drop to.
connectWith: "#list1",
over: function () {
removeIntent = false;
},
out: function () {
removeIntent = true;
},
beforeStop: function (event, ui) {
itemContext = ui.item.context;
if (removeIntent == true) {
ui.item.remove();
disp($("#list2").sortable('toArray'));
}
//console.log(itemContext);
},
receive: function (event, ui) {
console.log(ui);
console.log(event);
var this_id = $(ui.item).attr("id");
var preview = $(itemContext).html().replace(/<!--/g, '').replace(/-->/g, '');
$(itemContext).attr("id", this_id);
$(itemContext).css("width", $('#list2').width() - 20).addClass("ui-state-default").height('auto');
$(itemContext).html(preview);
//console.log(this_id);
//console.log(preview);
}
}); //.disableSelection()
//end of modified code
//console.log(this_id);
//console.log(preview);
}
});
WORKING DEMO, full code