JQuery Draggable + Sortable: How to tell if item w

2019-02-28 11:59发布

问题:

OK, I'm probably missing something obvious here, but my searches aren't turning up anything helpful. I've set up a sortable list and connected a draggable "palette list" to it, as explained here: http://jqueryui.com/demos/draggable/#sortable

I can drag items from my draggable list and drop them on my sortable list. That works fine.

I need to fire a function only when one of these items is dropped onto the sortable.

I've tried the "stop" hook on the draggable item, but that fires regardless of where the item is dropped (it fires if revert: 'invalid' is triggered, for example). I can't find any properties anywhere to tell me whether the drag was successful or not.

I've tried treating the sortable as a "droppable" and binding to "drop", but that doesn't even get called.

Thanks for the help!

回答1:

Found it!

Sortable has an event called receive. http://api.jqueryui.com/sortable/#event-receive

How I missed this in the past few hours of digging is beyond me.