我有部分,每個部分都有項目。這些項目是可排序的對象,我可以從一個部分拖放到另一個部分。我們的一些客戶有TON部分的TON項目,使得瀏覽器陷入膝蓋。當我最初設計它的時候,我很綠,所以效率並不是真的在我的雷達上,但現在我正在重新審視劇本,並且遇到了一個問題。有沒有辦法在拖拽可排序項目時刷新排序?
爲了解決這個問題,我在我的部分列表中使用ajax進行延遲加載,其中只有在點擊「打開部分」按鈕時才從服務器獲取項目。我們在效率低下的系統中的一個特點是,用戶可以將拖動的項目放在關閉部分上500毫秒,並打開該部分。
這是生成的HTML:
<ul class="sections ui-sortable" style="display: block;">
<li id="s_3" class="ui-droppable">
<input type="hidden" value="3" name="section_id">
<span class="sectionName">Section 1</span>
<ul class="items ui-sortable" style="">
<!-- Items can go here -->
</ul>
</li>
<li id="s_11" class="ui-droppable">
<input type="hidden" value="11" name="section_id">
<span class="sectionName">Section 2</span>
<ul class="items ui-sortable" style="display: block;">
<li id="i_32">
<input type="hidden" value="32" name="item_id">
<span class="itemName">Item 1</span>
</li>
</ul>
</li>
</ul>
我的問題是,排序功能得到所有screwie用新填充的項目列表。
這是我如何使它所以列表可以將鼠標懸停在打開:
//sElement is the .sections ul
function initItemDroppable(sElement) {
sElement.find('> li').droppable({
accept: '.items > li',
over: function(event, ui) {
var section = $(this);
var section_id = section.find('input[name="section_id"]').val();
// only start the counter if the container isn't already visible
if(!$(section).find('.items').is(':visible')) {
$(document).oneTime('500ms', 'expandCategoryTimer', function(){
//get the items and populated the list
getItems(section_id);
//according to jquery, refreshes the positions of all the sortable objects
$('.sections, .items').sortable('refreshPositions');
});
}
},
out: function(event, ui) {
$(document).stopTime('expandCategoryTimer');
}
});
}
我想我只需要在排序東西「refreshPosition」的方法,但它並不完全這樣做的伎倆。我可以在列表的末尾放置一個項目,但是我不能將它放在其他項目之間,除非我放棄它並重新選擇它。有任何想法嗎?