jQuery Draggable ConnectTosortable可保持原始
我有以下方案:我正在编写一个简单的MIDI工具,有2个列表,左侧的一个是可分类的,用于从右侧删除项目(左侧是要使用的注释列表,右边是注意我可以使用)。当我将笔记拖到左侧时,它将从右侧删除,因此我无法再次添加此注释。
我如何停止在掉落后删除原始元素?我试图在停止事件中克隆它,但是这在左侧创建了2个注释,并从右侧删除,我还尝试在开始事件中克隆物品,但是当掉落时,它将被删除。
我没有看到这种情况的任何示例,其中大多数是要添加可辍学的示例,但是我使用可分配的,这肯定是一样的吗?
这是我脚本的相关部分:
$(".alloc").draggable(
{
connectToSortable: ".playList",
helper: "clone",
snap: true,
refreshPositions: true,
stack: ".notes",
handle: ".note-head",
start: function (_event, ui) {
let li = ui.helper;
li.clone().insertAfter(li);
},
stop: function (_event, ui) {
let li = ui.helper;
let ol = li.parent();
li.removeClass("bank");
li.addClass("note");
let id = li.attr( "id");
let value = li.attr( "data-value");
let data = {
_token: $('#token').val(),
id: id,
value: value
};
$.post( "/note/add", data )
.done( function( result ) {
// Update if needed...
});
}
}
);
$(".playList").sortable(
{
connectWith: ".notes",
placeholder: "ui-state-highlight h-full",
distance: 4,
helper: "clone",
receive: function (_event, ui) {
ui.item.remove();
}
}
);
如何将正确的列表保留在可排序的左列表中?
谢谢
I have the following scenario: I'm writing a simple midi tool, I have 2 lists, the one on the left is sortable and is used to drop the items from the right (left is the list of notes to use and right is the notes I can use). When I drag my note to the left it is removed from the right so i can't add this note again.
How can i stop the original element being removed after the drop? I tried to clone it in the stop event but this created 2 notes on the left and removed from right, I also tried cloning the item in the start event but again when dropped this is removed.
I've not seen any examples for this scenario with most being to add droppable but I'm using sortable, surely this is the same right?
Here is the relevant section of my script:
$(".alloc").draggable(
{
connectToSortable: ".playList",
helper: "clone",
snap: true,
refreshPositions: true,
stack: ".notes",
handle: ".note-head",
start: function (_event, ui) {
let li = ui.helper;
li.clone().insertAfter(li);
},
stop: function (_event, ui) {
let li = ui.helper;
let ol = li.parent();
li.removeClass("bank");
li.addClass("note");
let id = li.attr( "id");
let value = li.attr( "data-value");
let data = {
_token: $('#token').val(),
id: id,
value: value
};
$.post( "/note/add", data )
.done( function( result ) {
// Update if needed...
});
}
}
);
$(".playList").sortable(
{
connectWith: ".notes",
placeholder: "ui-state-highlight h-full",
distance: 4,
helper: "clone",
receive: function (_event, ui) {
ui.item.remove();
}
}
);
How do I keep the right list as it is and just clone into the sortable left list?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从可分配中删除了
ui.item.remove();
,并根据需要起作用。I removed the
ui.item.remove();
from sortable and it worked as required.