删除项目时刷新jquery.com
通过Ajax删除项目时,如何刷新?这是我用来删除项目的代码:删除项目时刷新jquery.com,jquery,jquery-masonry,Jquery,Jquery Masonry,通过Ajax删除项目时,如何刷新?这是我用来删除项目的代码: if($deletes = $('a[rel=delete]')) { $deletes.click(function() { if(!window.confirm('Are you sure you wish to delete this picture?')) return false; $t = $(this); $.post(
if($deletes = $('a[rel=delete]')) {
$deletes.click(function() {
if(!window.confirm('Are you sure you wish to delete this picture?'))
return false;
$t = $(this);
$.post(
$t.attr('href'),
{},
function(data) {
if(data == "success")
$t.parents('.deleteable:first').fadeOut();
}
);
return false;
});
}
我希望刷新的原因是在删除项目后消除产生的空格。我认为只需在选择器上再次调用它即可。看来得看看有没有人再叫
...snip...
// checks if masonry has been called before on this object
props.masoned = !!$wall.data('masonry');
...snip...
我还建议使用
saveOptions
设置,因为它似乎支持重新调用。没关系,默认情况下,它似乎是这样做的(哦!)将回调添加到您的fadeOut()
中,以实际调用。删除(
)已删除的元素,一旦它淡出,就再次调用容器上的.massy()
。在fadeOut callback中再次调用massy。让这对你自己来说很容易,并在函数中进行初始化。在其中定义选项,这样就不必将选项带入回调范围
像这样
$(function(){
var $bricks = $('your > elements');
function BuildWall(){
$bricks.masonry({your:'options'});
}
BuildWall();
//Your code modified
if($deletes = $('a[rel=delete]')) {
$deletes.click(function() {
if(!window.confirm('Are you sure you wish to delete this picture?'))
return false;
var $t = $(this);
$.post(
$t.attr('href'),
{},
function(data) {
if(data == "success")
$t.parents('.deleteable:first').fadeOut(function(){
//This is faster than $(this).remove();
$(this).empty().remove();
//Reset Masonry
BuildWall();
});
}
);
return false;
});
}
});
jquery本身有一个remove方法() 您可以将其放入淡出回调中:
$("your-container").masonry( 'remove', $(this) ).masonry();
我尝试再次调用它,但没有效果:$('.mashise wrapper').mashise({columnWidth:188,singleMode:true,itemSelector:'.item'});请考虑选择正确的答案。感谢这个有用的提示。很适合我的项目。