当我拖放项目时,使用sortupdate
跟随代码会被触发
$('#sortable').sortable().bind('sortupdate', function (event, ui) {
debugger;
//Triggered when the user stopped sorting and the DOM position has changed.
});
BUT
start
,update
,stop
,change
事件未被触发
即,
$('#sortable').sortable({
start: function(event, ui) {
//
},
change: function(event, ui) {
//
},
update: function(event, ui) {
//
}
});
我的目标是找到商品的原始和已删除位置。
编辑(为了清楚了解):
简而言之,
$('#sortable').sortable().bind('sortupdate' .....
正在工作(已触发)
$('#sortable').sortable().bind('start' .....
无效(未触发)
$('#sortable').sortable().bind('change' .....
无效(未触发)
$('#sortable').sortable().bind('update' .....
无效(未触发)
$('#sortable').sortable().bind('sort' .....
无效(未触发)
如果可以单独使用sortupdate
事件来获取旧位置和新位置的值,那么也可以。我的最终目标是找到项目的旧位置和新位置。
答案 0 :(得分:0)
所有这些事件都以sort为前缀,因此不是start而是sortstart 我已经创建了一个小提琴,它将提供项目的消息,并在
处进行检查$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
var from,to;
$("#sortable").on("sortstart",function(event,ui){
from = $(this).children().index(ui.item);
});
$('#sortable').on('sortdeactivate',function(event,ui) {
to = $(this).children().index(ui.item);
alert(ui.item.text()+' moved from '+(from + 1)+' to '+(to + 1));
});
答案 1 :(得分:0)
这是将事件绑定到jquery sortable
的正确方法$( ".selector" ).sortable({
start: function( event, ui ) {}
});
OR
$( ".selector" ).on( "sortstart", function( event, ui ) {} );