从可排序的事件更新中获取helper(Draggable)中的内容

时间:2013-05-26 14:31:19

标签: jquery jquery-ui draggable jquery-ui-sortable helper

如何从可从对象排序的事件“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();
  });

1 个答案:

答案 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();
});