admin管理员组文章数量:1386651
Im trying to add a fuzzy search library to my project via fuse.js. I include the following lines and I'm getting a constructor error, I tried to re-install fuse but I'm wondering where the error may be.
// 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
Im trying to add a fuzzy search library to my project via fuse.js. I include the following lines and I'm getting a constructor error, I tried to re-install fuse but I'm wondering where the error may be.
// 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
Share
Improve this question
edited Jun 28, 2020 at 18:55
krisk
7,1171 gold badge19 silver badges30 bronze badges
asked Apr 20, 2017 at 22:43
learner561learner561
1372 silver badges11 bronze badges
2 Answers
Reset to default 8You're confusing the fuse.js module with the fuse module, which is a pletely different project. You can see that this is the case by looking at the "Install" section of the Fuse.js website.
To fix this, run npm install --save fuse.js
and fix line with the require to this:
var Fuse = require('fuse.js');
Are you using typescript?
You need to first install the library: run npm install --save fuse.js
.
Then import the library on top of the file that you are going to use the library:
import * as Fuse from 'fuse.js'
本文标签: javascriptFusejs constructor issueStack Overflow
版权声明:本文标题:javascript - Fuse.js constructor issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744525895a2610745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论