如何从可从对象排序的事件“update”中获取在draggable“helper”中声明的内容?
$(function() {
$( "#sortable" ).sortable({
revert: true,
update: function(event, ui){
??????
}
});
$( "#draggable" ).draggable({
connectToSortable: "#sortable",
helper: function(e){
return $('<div>sample</div>');
},
revert: "invalid"
});
$( "ul, li" ).disableSelection();
});
答案 0 :(得分:1)
你可以试试这个:
$(function () {
$("#sortable").sortable({
revert: true,
update: function (event, ui) {
var draggableHelper = $(this).data('helper');//setted in draggable start handler
}
});
$("#draggable").draggable({
connectToSortable: "#sortable",
helper: function (e) {
return $('<div>sample</div>');
},
revert: "invalid",
start: function (event, ui) {
$($(this).draggable('option','connectToSortable')).data('helper', ui.helper);
}
});
$("ul, li").disableSelection();
});