gpt4 book ai didi

jQuery UI 可排序 - 获取与 drop 相邻的项目

转载 作者:行者123 更新时间:2023-12-01 04:35:51 25 4
gpt4 key购买 nike

我有可排序的列表,在某些情况下我需要防止丢弃,具体取决于我在丢弃时“推到一边”的内容。这是一些伪代码:

    $('ul#SortableList').sortable( {connectWith: 'ul#OtherList',
beforeStop: function(ev, ui) {
// Need item(s) that are being "pushed" out of the way of the item being dropped
if (adjacentItem == condition)
{ // prevent the drop
$(this).sortable("cancel");
}

我知道“这个”会给我实际的列表本身被删除的内容,但我不知道如何让实际的项目被删除......或者甚至只是之前或之后的一个特定项目会让我继续正确的轨道。

最佳答案

弄清楚了:

    beforeStop: function(ev, ui)
var previousItem = ui.placeholder.parent().children().get(ui.placeholder.index() - 2); // 2 works here, probably because the placeholder AND the dropped item are counted
console.log(previousItem);
console.log(ui.placeholder);
var nextItem = ui.placeholder.parent().children().get(ui.placeholder.index() + 1);
console.log(nextItem);
console.log(ui.placeholder.parent());
}

关于jQuery UI 可排序 - 获取与 drop 相邻的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55876546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com