2017-04-20 169 views
1

我试图通过fuse.js添加一个模糊搜索库到我的项目中。我包括以下几行,我得到一个构造函数错误,我试图重新安装保险丝,但我想知道错误可能在哪里。Fuse.js构造函数问题

//TypeError: Fuse is not a constructor 





var Fuse = require('fuse'); 



var options = { // list of options that need to be provided to fuse.js for search to occur 
    shouldSort: true, 
    threshold: 0.6, 
    location: 0, 
    distance: 100, 
    maxPatternLength: 32, 
    minMatchCharLength: 1, 
    keys: [ 
    "title", // the keys that are searched 
    "decription" 
] 
}; 

var fuse = new Fuse(posts, options); // "list" is the item array 
var result = fuse.search(searchOptions.keywords); // search is conducted and result should be all matching json objects 

回答

2

你混淆了fuse.js模块与模块fuse,这是一个completely different project。您可以通过查看Fuse.js网站的"Install"部分来了解情况。

为了解决这个问题,运行npm install --save fuse.js和修复符合要求这样:

var Fuse = require('fuse.js');