无法获得同位素按数字排序

时间:2014-11-15 00:56:07

标签: jquery sorting jquery-isotope

我试图让同位素按p.number中的数字排序(每个div.box中有一个p.number),所有div.box都在#content中(我的jquery在下面是建立这个标记)但是现在所有的div.box div都只是堆叠在一起 - 我想要的是当我点击按钮时,div.box将按照找到的数字排序p.number标签

这是我在Web控制台中遇到的错误:TypeError:' .number parseInt'不是一个功能(评估' ea')

<body>
    <div class="wrapper">
        <div id="sorts">
            <button>sort by number</button>
        </div>
        <div id="content">
        </div> 
    </div>

    <script>        

        var myData = [
    {
        "number" : "15", 
        "promoimage_title" : "Title here item 1"
    },
    {
        "number" : "28",
        "promoimage_title" : "Title here item 2"
    },
    {
        "number" : "58",
        "promoimage_title" : "Title here item 3"
    },
    {
        "number" : "37",
        "promoimage_title" : "Title here item 4"
    },
    {
        "number" : "4",
        "promoimage_title" : "Title here item 5"
    },
    {
        "number" : "8",
        "promoimage_title" : "Title here item 6"
    },
    {
        "number" : "23", 
        "promoimage_title" : "Title here item 7"
    },
    {
        "number" : "88",
        "promoimage_title" : "Title here item 8"
    },
    {
        "number" : "27",
        "promoimage_title" : "Title here item 9"
    },
    {
        "number" : "67",
        "promoimage_title" : "Title here item 10"
    }

];


        $.each(myData, function(index, value) {
                $('#content').append("<div class='box'><p class='number'>"+value.number+"</p><p class='box-title'>"+value.promoimage_title+"</p></div>");
        });

        var $container = $('#content');                 

          $container.isotope({
            itemSelector: '.box',
            layoutMode: 'masonry',
            getSortData: {
              number: '.number parseInt'
            }
          });



        $('#sorts').on( 'click', 'button', function() {
            $container.isotope({ sortBy: 'number' });
        });


    </script>
</body>

0 个答案:

没有答案