Vì vậy, những gì bạn muốn đạt được có thể được tóm tắt như thế này
Bước 1: Kéo và thả một số Layout (đó là bên li
tag) #list3
-#list2
.
Bước 2: Kéo và thả một số phương tiện truyền thông (mà cũng là bên trong li
thẻ) từ #list1
-#list2
trực tiếp và cũng có thể tag ul #list2
Layout của .drop-container
mà bây giờ đã được kéo đến #list2
.
Hiện tại, bạn đang giảm #list1 li
vào #list 2
, nhưng nó phải được thả vào .drop-container of #list2
hoặc #list2
(nếu bạn muốn thêm #list li
-#list2
trực tiếp)
nên #list1 li
nên được kết nối với .drop-container of #list2
và #list2
$("#list1 li").draggable({
connectToSortable: "#list2 .drop-container,#list2",//both element should be connected
helper: "clone",
revert: "invalid",
greedy: true
});
Sau đó, cần thêm sortable
API vào .drop-container of #list2
o nly sau #list2
đã nhận được một số Layout từ #list3
của
Vì vậy, gọi sortable
trên #list2 .drop-container
bên nhận phương pháp sortable
của list2
. Bây giờ bạn nhận được chức năng của #list2
trở thành
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
Bạn muốn sắp xếp các mặt hàng và kéo/thả giữa danh sách? Hoặc khác? –
Tôi muốn kéo và thả các mục giữa các danh sách có nghĩa là lần đầu tiên tôi thả mục vào danh sách 2 từ danh sách3 và sau đó tôi sẽ thả vào khu vực bên trong của mục bị mất từ danh sách1 –
Bố cục kéo đầu tiên1 và trong đó muốn kéo phương tiện –