我有两个通过 jQuery 可排序连接的列表。这些列表彼此相邻 float 。右侧列表中的列表项可以拖动到左侧列表中,左侧列表中的列表项不可拖动。
当我将列表项从右侧列表拖动到左侧列表时,我有一个检查,检查任何新连接的列表项是否最初来自右侧列表,如果是这种情况,则列表项通过 jQuery 删除函数删除。
stop: function (event, ui) {
var nextItemclass = ui.item.next().attr("class");
var prevItemClass = ui.item.prev().attr("class");
if ((nextItemclass == "sortableRow") && (ui.item.parent().hasClass('static'))) {
ui.item.next().remove(); //in stead of Remove I want this item to reset to it's original UI
}
if ((prevItemClass == "sortableRow") && (ui.item.parent().hasClass('static'))) {
ui.item.prev().remove(); //in stead of Remove I want this item to reset to it's original UI
}
}
现在,我不想完全删除列表项,而是希望将其返回到原始列表,即右侧的列表。
所以我希望将代码 ui.item.prev().remove();
更改为将列表项重置为其原始列表的代码。我也在我的原始代码中对此进行了评论。
这是我的完整代码:
您会注意到,如果将两个不同的可排序项目拖动到不可排序项目下方,则第一个项目将被完全删除。我希望以这样的方式更改代码,以便首先存在的列表项将重置为其原始列表,而不是完全删除。
最佳答案
关于jquery - 如何重置可排序 jquery 列表中的列表项而不是完全删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20067434/