简体   繁体   English

关于使用HTML Select选项对jQuery同位素进行排序的问题

[英]Issue on Sorting jQuery Isotope Using Html Select Option

Using jQuery and isotope plugin I have some issue on sorting items by changing dropdown list. 使用jQuery和同位素插件,我在通过更改下拉列表对项目进行排序时遇到一些问题。 Can you please take a look at this demo and let me know why I am not able to sort the isotope container when I select a sort value? 您能否看一下这个演示 ,让我知道为什么当我选择一个排序值时为什么不能对同位素容器进行排序?

Here is the part which I am using for sorting 这是我用于排序的部分

  $('#sorts').on( 'change', function() {
    var sortByValue = this.value;
      console.log(sortByValue);
    $container.isotope({ sortBy: sortByValue });
  });  

and here is the whole isotope part code: 这是整个同位素的部分代码:

$( function() {
  // init Isotope
  var $container = $('.isotope').isotope({
    itemSelector: '.element-item',
    layoutMode: 'fitRows'
  });
  // filter functions
  var filterFns = {
    // show if number is greater than 50
    numberGreaterThan50: function() {
      var number = $(this).find('.number').text();
      return parseInt( number, 10 ) > 50;
    },
    // show if name ends with -ium
    ium: function() {
      var name = $(this).find('.name').text();
      return name.match( /ium$/ );
    }
  };
  // bind filter on select change
  $('#filters').on( 'change', function() {
    // get filter value from option value
    var filterValue = this.value;
    // use filterFn if matches value
    filterValue = filterFns[ filterValue ] || filterValue;
    $container.isotope({ filter: filterValue });
  });

   // bind sort button click
  $('#sorts').on( 'change', function() {
    var sortByValue = this.value;
      console.log(sortByValue);
    $container.isotope({ sortBy: sortByValue });
  });  

});

i have checked this example, see if it works 我已经检查了这个例子,看看是否有效

$('.isotope').isotope({
    itemSelector: '.element-item',
    layoutMode: 'fitRows',
    getSortData: {
      name: '.name',
      symbol: '.symbol',
      number: '.number parseInt',
      category: '[data-category]',
      weight: function( itemElem ) {
        var weight = $( itemElem ).find('.weight').text();
        return parseFloat( weight.replace( /[\(\)]/g, '') );
      }
    }
  });

check the example in the website 网站上查看示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM