问题描述
以下代码未完全禁用start事件的sortables。它会将类 ui-sortable-disabled
和 ui-state-disabled
添加到可排序元素中,但它不会禁用该功能 - 换句话说,sortables看起来已禁用,但它们仍然接受拖动的项目并且表现得像启用它们一样。
The below code does not fully disable the sortables on the start event. It will add the classes ui-sortable-disabled
and ui-state-disabled
to the sortable elements, but it doesn't disable the functionality - in other words, the sortables look disabled, but they still accept the dragged item and behave like they are enabled.
var assignedSortables;
var startDrag = function(event, ui) {
assignedSortables.each(function() {$(this).sortable('disable');});
};
var stopDrag = function(event, ui) {
assignedSortables.each(function() {$(this).sortable('enable');});
};
assignedSortables = $(".my-sortable-containers").sortable({
connectWith: '.my-sortable-containers',
start: startDrag,
stop: stopDrag
});
我想要执行此操作的原因是拖动启动是因为我可能需要禁用其他连接的可排序已经包含被拖动的项目(我为了简化而剥离了逻辑)。这是一个错误还是有办法吗?
The reason I want to do this is on drag start is because I might need to disable other connected sortables that already contain the item being dragged (I stripped out the logic in order to simplify). Is this a bug or is there a way around it?
推荐答案
我还没有检查过jQuery库是否已修复 这是因为我问了这个问题,我做的是使用mousedown和mouseup事件来禁用和启用
I have not checked to see if the jQuery library has "fixed" this since I asked the question, what I did instead was use the mousedown and mouseup events to disable and enable
$(".myDraggableContainer").mousedown(functionToDisableTheCorrectSortables).mouseup(functionToEnableSortables);
这样做实际上会完全禁用接收排序
Doing it this way does in fact disable the receiving sortables fully
这篇关于jQuery sortable('disable')来自start事件并不像预期的那样完全正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!