更换 div 后同位素不起作用

Isotope not working after I replace a div

我有 jQuery post 用更新的产品替换 div。网格是用同位素格式化的,但我不知道如何让它在更新后重新格式化网格。

$.post(url, function(data) {

    $('#product_list').first().replaceWith(data.products);

}).always($('#product_list').isotope({
    itemSelector: '.product-thumb-info-list'
}));

如果我从控制台 运行 isotope() 它将很好地重新排序网格,所以我猜它触发得太早了。

如何在 post 函数替换 div 后立即应用到网格?

你能否改变你处理 always 方法的方式:

$.post(url, function(data) {
  $('#product_list').first().replaceWith(data.products);
}).always(function() {
  $('#product_list').isotope({
    itemSelector: '.product-thumb-info-list'
  })
});