如果对确认框的回复是否定的,我正在尝试取消对删除功能的可排序。这是我可排序的无序列表。
$("#items").sortable({
remove: function(event, ui) {
var id = ui.item.attr("id");
var loadUrl = "LoadItem.action";
var removeUrl = "RemoveItem.action";
$.getJSON(loadUrl, {"id":id}, function(data){
if (data.passed !== undefined){
var answer = confirm("A status exists on this item. Remove anyways?");
if (!answer){
$(this).sortable('cancel'); //<-- This is where I need help
return false;
}
$.post(removeUrl, {"id":id}, function(){
//alert('removed');
});
}
});
}
});
当我点击取消时,它会阻止我的$.post(removeUrl);
按预期触发,但该订单项仍会移至另一个可排序列表。我希望它取消订单项移动。在接收事件中使用$(ui.sender).sortable('cancel');
以这种方式工作,但有没有办法在remove事件中执行相同的操作?
答案 0 :(得分:1)
$("#items").sortable({
remove: function(event, ui) {
var id = ui.item.attr("id");
var loadUrl = "LoadItem.action";
var removeUrl = "RemoveItem.action";
var self = this;
$.getJSON(loadUrl, {"id":id}, function(data){
if (data.passed !== undefined){
var answer = confirm("A status exists on this item. Remove anyways?");
if (!answer){
$(self).sortable('cancel');
return false;
}
$.post(removeUrl, {"id":id}, function(){
//alert('removed');
});
}
});
}
});