jquery 可排序 droponempty 修复
我正在使用 jQuery 的可排序(jQuery ui)
,默认 dropOnEmpty = true
,并且作为加速,我正在应用 connectwith
之后我将.sortable()
应用到我的选择器,如下所示:
<script type="text/javascript">
$('#selector1').sortable({
over: function(ev,ui){
console.log('Dragging over: '+$j(ui.placeholder).parent().parent().parent().attr('id'));
}
)};
$('#selector2').sortable({
over: function(ev,ui){
console.log('Dragging over: '+$j(ui.placeholder).parent().parent().parent().attr('id'));
}
)};
$('.ui-sortable').sortable('option', connectWith', '.ui-sortable');
</script>
我已经演示了我的日志记录来尝试弄清楚发生了什么 - 想象我第一次拖动从 #selector1 到#selector2(为空)- 没有出现日志记录,但是如果我拖回到源中,我会得到日志记录,而当我拖回目标列时它会起作用吗?
空选择器甚至有 ui-sortable 类,但它没有连接!
在单独初始化 connectWith
后应用 connect-with 时,我应该如何确保即使是空列表?
I am working with jQuery's sortable (jQuery ui)
By default dropOnEmpty = true
, and as a speedup I'm applying the connectwith
after I apply .sortable()
to my selectors as follows:
<script type="text/javascript">
$('#selector1').sortable({
over: function(ev,ui){
console.log('Dragging over: '+$j(ui.placeholder).parent().parent().parent().attr('id'));
}
)};
$('#selector2').sortable({
over: function(ev,ui){
console.log('Dragging over: '+$j(ui.placeholder).parent().parent().parent().attr('id'));
}
)};
$('.ui-sortable').sortable('option', connectWith', '.ui-sortable');
</script>
I've demonstrated my logging to try to figure out what's going on - Imagine I first drag from #selector1 to #selector2 (which is empty) - no logging appears, but than if I drag back into the source, I get the logging, and than when I drag back into the target column it works?
The empty selector even has ui-sortable
class but it's not connecting!
How should I make sure that even the empty lists while applying the connect-with after initializing the the connectWith
separately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://jsfiddle.net/MMyP3/5/
编辑:代码按照要求:
HTML:
CSS:
Javascript:
编辑:我更新了我的链接,我认为主要问题是我调整的html结构,还要确保将元素拖动到空的顶部
div
。仅仅因为您正在更改背景颜色和最小高度并不意味着实际可排序的高度正在改变。因此,看起来您可以将项目放置在开放区域的任何位置,但实际上您不能,除非您一开始就定义了可排序的高度。http://jsfiddle.net/MMyP3/5/
EDIT: Code as requested:
HTML:
CSS:
Javascript:
Edit: I updated my link, I think the main issue was your html structure which I adjusted, also make sure you are dragging the elements to the top of the empty
divs
. Just because you are changing the background color and min-height doesn't mean the actual sortable's height is changing. So it may look like you can place the items any where in the open area, in reality you actually can't, unless you define heights for the sortables on the get go.@Jack 关于为什么不能放入空排序的解释是正确的。在运行任何回调之前,可排序在拖动开始时缓存其可排序的位置。因此,如果您在回调中更改放置区域的高度,这些高度将被忽略,因为它仍然使用缓存的值。
如果您在调整高度后立即使用 Sortable 的 'refreshPositions' 方法回调中,可排序现在应该具有准确的定位信息,以便您可以成功放入目标区域,而无需触摸非空可排序列表。
@Jack's explanation of why you can't drop into empty sortables is correct. Sortable caches the positions of its sortables at the beginning of a drag start before any callbacks have been run. So if you change the height of the drop zones in the callback, those are ignored as it still uses cached values.
If you use the Sortable's 'refreshPositions' method just after you adjust the height in your callback, the sortable should now have accurate positioning info so that you can successfully drop in the target zone without having to touch a non-empty sortable list.