【发布时间】:2011-03-26 22:21:57
【问题描述】:
我在一个页面上有许多 div 溢出:自动,许多 li 的数量超出了可见区域的容量。当我从一个 div 拖放到另一个 div 时,如果目标 div 上方的 div 有一个长列表,则 $(this) 将返回该 div 的 id,而不是我的项目所在的 div。在视觉上和在修改后的 html 中它工作正常,但我需要能够获得它所在的 div 的 id 并且似乎无法弄清楚。似乎必须有一个解决方法???
我的目标是可靠地获取接收 div 的 id。到 drop 事件触发时,该位置尚未更改。也许它可以通过 id 以相反的顺序初始化每个可放置的 div,而不是使用“可排序”类,但可以有 10 或 15 个,而且看起来非常笨拙。
这是我的初始化代码(在尝试 greedy:true 之后):
$( ".sortable" ).sortable({
connectWith : ['.sortable'],
dropOnEmpty : true,
placeholder : "ui-state-highlight",
revert: true,
start : function(event, ui) {
getEquip($(ui.item).attr('id').slice(8));
}
});
$( ".sortable" ).draggable({
helper: "clone",
revert: "invalid"
});
$( ".sortable" ).droppable({
greedy : true,
drop: function( event, ui ) {
var msg = 'Moved ' + $(ui.draggable).text() + ', id#' + $(ui.draggable).attr('id').slice(8) + ' to';
msg += ' ' + $(this).attr('id'); //<<== gives wrong id if list above is long
msg += ' ' + $('#' + $(ui.draggable).attr('id')).parent().attr('id');
writeFooter(msg);//Moved hydrant wrenches, id#164 to sortable16 sortable22
},
});
【问题讨论】:
-
您是否将选项
greedy: true添加到您的可放置对象中?请提供一些代码,以便我们为您提供帮助 -
感谢您的回复!我尝试贪婪没有成功,并在上面添加了一些代码。