我希望能够在拖动操作开始后停止/取消拖动操作,例如按 Esc 键。我正在基于 Primefaces Showcase 示例工作。https://www.primefaces.org/showcase/ui/dnd/dataTable.xhtml
<h:form id="carForm">
<p:dataTable id="availableCars">
<p:column>
<h:outputText id="dragIcon" styleClass="ui-icon pi pi-plus"/>
<p:draggable id="draggable" for="dragIcon" revert="true" helper="clone"/>
</p:column>
</p:dataTable>
<p:outputPanel id="droppedArea">
<!-- Here, there is a datatable where dragged rows are shown -->
<p:dataTable id="selectedCars">
...
</p:dataTable>
</p:outputPanel>
<p:droppable for="droppedArea" tolerance="touch" datasource="availableCars">
<p:ajax listener="#{actionView.onDrop}" update="availableCars selectedCars" />
</p:droppable>
</h:form>
在 keyup 事件中,我尝试了很多方法来恢复 drop 事件,甚至将事件发送到未删除的位置。我也尝试过修改 PrimeFaces.widget.Droppable.prototype.bindDropListener 函数。
<script type="text/javascript">
//detect Escape key press
document.addEventListener("keyup", function(event) {
if(event.keyCode === 27){
$('.ui-draggable:data(draggable)').draggable( 'option', 'revert', true ).trigger( 'mouseup' );
}
});
</script>