我正在寻找一种方法,如果某些东西不能验证,则从恢复状态触发事件,例如,如果元素存在,它将从另一个列表创建它,但如果它已经存在,它应该转到else并返回元素到原来的位置:
$( "#catalog ul" ).droppable({
tolerance: 'fit',
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
//check if already exists
if($(this).find("#"+$(ui.draggable).attr("id")).length==0){
$( "<li id="+$(ui.draggable).attr("id")+"></li>" ).text( ui.draggable.text() ).appendTo( this )
.draggable({
revert: 'invalid',
stop: function(){
$(this).draggable('option','revert','invalid');
}
}).droppable({
greedy: true,
tolerance: 'touch',
drop: function(event,ui){
ui.draggable.draggable('option','revert',true);
}
});
}else{
//want to make the object go back by setting true to revert
return false;
}
}
})
答案 0 :(得分:11)
感谢Kenji,这确实有效:
ui.draggable.draggable('option','revert',true);
我一直在努力争取一个早上,直到找到你的帖子,谢谢
答案 1 :(得分:0)
.droppable({
greedy: true
}
这个选项也一定需要