jQuery UI 可拖动 - 如果发生有效的放置,则删除克隆
我试图让类似以下的内容起作用,但找不到为此使用停止事件的正确方法。
我有两列,您可以从右向左拖动。如果放置无效,我的恢复功能可以正常工作,但如果左列发生有效放置,我想删除右列中的项目。我知道条件不正确,但我不确定要查找什么标志来确定丢弃是否有效。
$("#sortable2 li").draggable({
connectToSortable: "#sortable1",
helper: "clone",
revert: "invalid",
stop: function (event, ui) {
if (drop == "valid")
{
$(this).remove();
}
}
});
I'm trying to get something like the following to work but can't find the correct way to use the stop event for this.
I've got two columns where you can drag from the right to the left. I've got the revert function working correctly if the drop was invalid but I want to remove the item in the right column if a valid drop occurred on the left column. I know the conditional isn't correct but I'm not sure what flag to look for to determine if the drop was valid.
$("#sortable2 li").draggable({
connectToSortable: "#sortable1",
helper: "clone",
revert: "invalid",
stop: function (event, ui) {
if (drop == "valid")
{
$(this).remove();
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
.sortable
上的receive
事件来删除原始元素示例 jsfiddle
you can handle removing the original element using the
receive
event on the.sortable
example jsfiddle
首先,您可以比较 event-start 和 事件停止。使用调试器进入事件函数,您可以看到两者之间的区别。
As a start you can compare the differences between event-start and event-stop. Use a debugger to break into the Event Function and you can see the difference between the two.
如果您没有对任何内容进行排序,并且希望在放置有效时删除原始项目,则只需删除
helper:"clone"
即可。If you are not sorting anything and want the original item to be remove as the drop is valid, you can just remove the
helper:"clone"
.