我所拥有的只是这个例子:http://jqueryui.com/sortable/现在我想要一个“魔术”事件告诉我,例如我将item5移动到item2并告诉我“5移动到2”位置
答案 0 :(得分:1)
不,我认为根据api没有“魔法”事件,但这是一种方法:
var startArray, stopArray;
$("#sortable").sortable({
start: function(){ //save items in array before they are sorted
startArray = $(this).sortable('toArray');
},
beforeStop: function(){ //save new sortorder of items
stopArray = $(this).sortable('toArray');
},
update: function(){ //if the dom is changed, check the differences
$.each(stopArray, function(index, value){
if(startArray[index] !== value){ //if the values don't fit, they are changed
console.log(value + ' is now on position ' + (index+1));
}
});
}
});
<强> Demo 强>
<强>参考强>