感謝來自@JulienGrégoire指着我的方向是正確的評論,我最終加入以下我排序的代碼來完成我需要的東西:
$("ul.my_sortable").sortable({
...
start: function (event, ui) {
// get placeholder position when selecting item
place_prev = ui.placeholder.prev();
start_col = $(this);
target_col = $(this)
},
change: function (event, ui) {
// keep track of where the placeholder moves...
place_pos = ui.placeholder.index();
// and reset it back to its starting position so it doesn't appear to move
place_prev.after(ui.placeholder);
},
beforeStop: function (event, ui) {
// move the choice to the correct column when you let go
if (!target_col.is(start_col)) {
target_col.append(ui.item);
}
}
});
這似乎仍然有點低效雖然,不斷保姆佔位符。如果其他人能想出更好的方法,我很樂意聽到它!
請參閱http://stackoverflow.com/questions/30322532/jquery-ui-sortable-sort-only-on-drop-event/30387678#30387678。你可能會應用相同的邏輯,除了你可以設置位置到最後一個項目的結尾。 –