当属性在运行时发生更改时,jQuery同位素排序停止工作

当属性在运行时发生更改时,jQuery同位素排序停止工作,jquery,jquery-isotope,Jquery,Jquery Isotope,我试图用“number”属性对一些元素进行排序,如jQuery同位素插件演示所示。正如预期的那样,分拣工作正常。但是,当我在运行时更改sort字段的值时,它停止排序。 HTML: 请参阅:清除容器并向其添加更新的值,然后在其上应用重载项 $('#changeLink').click(function () { $('.element').each(function () { $(this).children().first().text(Math.floo

我试图用“number”属性对一些元素进行排序,如jQuery同位素插件演示所示。正如预期的那样,分拣工作正常。但是,当我在运行时更改sort字段的值时,它停止排序。 HTML:


请参阅:

清除容器并向其添加更新的值,然后在其上应用重载项

$('#changeLink').click(function () {
        $('.element').each(function () {
            $(this).children().first().text(Math.floor(Math.random() * (100 - 1) + 1));
        });
        var newitems = $('#container').html();
        $('#container').html('');
        $('#container').html(newitems)
  .isotope( 'reloadItems' ).isotope({ sortBy: 'number' });


    });

您只需要运行
$container.同位素('updateSortData')更改号码后

见:

注意:我注意到您使用的是同位素的过时版本,因此我已将其更新为最新版本

$(function () {
    var $container = $('#container');

    $container.isotope({
        itemSelector: '.element',
        getSortData: {
            number: function ($elem) {
                return parseInt($elem.find('.number').text(), 10);
            },

        }
    });

    $('#sortLink').click(function () {
        $('#container').isotope({
            sortBy: 'number',
            sortAscending: true
        });
    });


    $('#changeLink').click(function () {
        $('.element').each(function () {
            $(this).children().first().text(Math.floor(Math.random() * (100 - 1) + 1));
        });

    });

});
$('#changeLink').click(function () {
        $('.element').each(function () {
            $(this).children().first().text(Math.floor(Math.random() * (100 - 1) + 1));
        });
        var newitems = $('#container').html();
        $('#container').html('');
        $('#container').html(newitems)
  .isotope( 'reloadItems' ).isotope({ sortBy: 'number' });


    });