jQuery 可排序(“禁用”)从开始事件不完全按预期工作
下面的代码不会完全禁用开始事件上的可排序。 它将向可排序元素添加 ui-sortable-disabled
和 ui-state-disabled
类,但它不会禁用该功能 - 换句话说,可排序元素看起来被禁用,但它们仍然接受拖动的项目并表现得像启用一样。
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚遇到了同样的问题。 我能够通过在启动可排序对象上调用“刷新”方法来获取我想要禁用的已连接可排序对象(实际上)。
因此,在您的启动回调内部将类似于:
我猜想列表在触发启动事件之前在内部获取一组连接的和非禁用的列表,并且不会检查触发启动后该列表是否发生变化。
I just ran into the same issue. I was able to get the connected sortable that I wanted to disable to disable (for reals) by calling the 'refresh' method on the initiating sortable.
So, inside your start callback would be something like:
I guess that internally the list grabs the set of connected and non-disabled lists before the start event is triggered and does not check to see if that list changes after start is triggered.
自从我提出这个问题以来,我还没有检查 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
Doing it this way does in fact disable the receiving sortables fully