1

我有一个页面,其中有一个可排序的项目列表(一个具有“可排序”类的 div),它最初可以包含一些项目或为空。这些项目在页面上的另一个列表中,并且有一个“添加”按钮。单击添加时,它们会进入可排序列表。

当页面已经加载列表中的某些项目时,排序工作,但随后添加到列表中的项目不可排序,即当我单击它们的可拖动元素时没有任何反应。

这是相关的 javascript:最初我使用 setSortables 仅在页面加载时调用它,但在这里我每次将项目移动到可排序列表时都会再次调用它。

//move this item into the sortable list
function addAssetToQuestion(asset_id){
  asset_div = jQuery("#asset_"+asset_id);
  asset_div.slideUp("fast", function(){ 
    jQuery("#assets").append(asset_div);
    asset_div.find(".add-asset-button").hide();
    asset_div.find(".remove-asset-button").show();
    asset_div.find(".name").addClass("pointerhand");     
    asset_div.slideDown("fast");
    setSortables();
  });
}

//set up the sortable list
function setSortables(){
  $(".sortable").sortable({
    handle: '.name',
    start: function() { jQuery(".audioplayer-container").hide(); },
    stop:  function() { jQuery(".audioplayer-container").show(); }
  });
}

jQuery(document).ready(function(){
  setSortables();
});

谢谢,最大

4

1 回答 1

0

您是否尝试过调用刷新?http://docs.jquery.com/UI/Sortable#method-refresh

Otherwise, at first glance I might suggest as a temporary fix to call destroy() and then setSortables() each time you drop an item on the list...

于 2009-11-25T11:22:15.673 回答