我正在尝试通过 fuse.js 将模糊搜索库添加到我的项目中。我包含以下几行,但出现构造函数错误,我尝试重新安装 fuse ,但我想知道错误可能出在哪里。
// 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
"description"
]
};
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
最佳答案
你混淆了 fuse.js模块与 fuse模块,这是一个 completely different project .您可以通过查看 "Install" 来了解情况。 Fuse.js 网站的一部分。
要解决此问题,请运行 npm install --save fuse.js
并根据要求修复行:
var Fuse = require('fuse.js');
关于javascript - Fuse.js 构造函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43531090/