我正在使用可排序的 UI,每个项目中都有一个delete
按钮。这是删除功能:
$('.delete_item').click(function(){
$(this).closest('.grid_3_b').remove();
initSortable();
$(".sortable").sortable('refresh').trigger('update');
});
The div
如我所愿被删除,但没有update
数据发送到 PHP.. 所以我的脚本不会保存订单和删除的项目..
这是我的initSortable();
功能:
function initSortable() {
$( ".sortable" ).sortable({
items: '.grid_3_b, .dropable',
connectWith: ".sortable",
placeholder: "placeholder",
remove: function(event, ui) {
if(!$('div', this).length) {
$(this).next('.dropable').remove();
$(this).remove();
}
initMenu();
},
receive: function(event, ui) {
if( $(this).hasClass( "dropable" ) ) {
if( $(this).hasClass( "gallery__item--active" ) ) {
$(this).before( "<div class=\"dropable gallery__item sortable\"></div>" );
$(this).after( "<div class=\"dropable gallery__item sortable\"></div>" );
initSortable();
$(".sortable").sortable('refresh').trigger('update');
initMenu();
}
}
},
update : function () {
var neworder = new Array();
$('.sortable').each(function() {
var id = $(this).attr("id");
var pusharray = new Array();
$('#' + id).children('div').each(function () {
var art = $(this).attr("data-art");
var pos = $(this).attr("data-pos");
pusharray.push( {data:{'art':art, 'pos':pos}} );
});
neworder.push({'id':id, 'articles':pusharray});
});
$.post("example.php",{'neworder': neworder},function(data){});
initMenu();
}
}).disableSelection();
}
initSortable();
另外,remove
函数通常会在列为空时删除列,但在删除列中的最新项目时不起作用。这是因为未调用更新触发器吗?