如果在validation后我决定将元素移回?如何设置jquery-ui draggable revert为true?

我正在寻找一种方法来触发事件从恢复状态,如果某些事情没有validation,例如,如果元素存在,它将从另一个列表创建它,但如果它已经存在,它应该转到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){ $( "
  • " ).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; } } })

    谢谢Kenji,这确实有效:

     ui.draggable.draggable('option','revert',true); 

    我一直在努力争取一个早上,直到找到你的post,谢谢

     .droppable({ greedy: true } 

    这个选项也一定需要