2017-04-20 226 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');