将项目放入已删除的项目
<table id='list1' >
</table>
<ul id="list2" >
</ul>
<table id='list3' >
<tr><td>test<ul style="min-height: 100px;border:1px solid red" class="drop-container"></ul></td></tr>
</table>
我有以下代码
$( "#list3 li" ).draggable({
connectToSortable: "#list2",
helper: "clone",
revert: "invalid"
});
$( "#list1 li" ).draggable({
connectToSortable: "#list2",
helper: "clone",
revert: "invalid",
greedy: true
});
如何直接将list1项目放入list2,并通过拖放jquery的API将list2&#39; s ul
布局标记从list3中删除?
答案 0 :(得分:6)
所以你想要实现的目标可以像这样总结
第1步:将一些布局(位于
li
标记内)从#list3
拖放到#list2
。步骤2:拖放一些媒体(也在
li
标签内) 直接#list1
到#list2
以及#list2
布局的ul标记.drop-container
现已被拖到#list2
。
目前,您要将#list1 li
放入#list 2
,但应将其放入.drop-container of #list2
或#list2
(如果您要将#list li
添加到#list2
直接{1}}
所以#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
收到来自.drop-container of #list2
#list2
API才需要添加到#list3
请在sortable
#list2 .drop-container
的{{1}}内接听sortable
内的list2
。
现在,#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);
}
});