1

我正在使用list.js来搜索/排序一个运行良好的无序列表。但是,我想添加搜索一些包含数值的列。搜索时,它将返回等于或大于搜索值的所有项目。

示例
值: 24,65,95,104
搜索: 80
返回: 95,104

我怎样才能做到这一点?提前致谢。我还发现此代码可能会有所帮助:

$('.filter-2').on('click', function() {
  userList.filter(function(item) {
    var born = parseInt(item.values().born);
    console.log(born);
    if (born < 1986) {
      return true;
    } else {
      return false;
    }
  });
});
4

1 回答 1

1

在纯 JavaScript 中:

var  array = [24,65,95,104];
console.log(arr.filter(function (num){
    return number > 80;
}));

在 list.js 中,它与filter 方法非常相似:

itemsInList = [
    { id: 1, name: "Jonny" }
  , { id: 2, name: "Gustaf" }
  , { id: 3, name: "Jonas" }
];

listObj.filter(function(item) {
    return item.values().id > 1;
}); // Only items with id > 1 are shown in list
于 2018-02-03T17:55:41.107 回答