我使用http://fusejs.io/搜索一些json数据。 这些数据是柜子的大清单,每个柜子都包含n个项目。
数据示例:
{"cabinets":[
{"cabinet":"A4","items":[
{"title":"Toys","keywords":"leksaker, pingpong, kendama, pingis","id":"98"},
{"title":"Skisch Grand Prix","keywords":"Pokal, cup, pris, skisch","id":"99"},{"title":"Lamp prototype","keywords":"lamp-prototyp","id":"100"}]},
{"cabinet":"B4","items":[
{"title":"Screens (LCD)","keywords":"skärm display","id":"30"},
{"title":"Displays","keywords":"screen skärm","id":"31"},
{"title":"Lampor","keywords":"","id":"32"}]}
...
搜索会查看项目的标题和关键字,我希望它返回匹配项目的ID。
.then(function (response) {
$scope.cabinets = response.data.cabinets;
var options = {
shouldSort: false,
threshold: 0.3,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 2,
keys: ["items.title","items.keywords"],
id: "items.id"
};
fuse = new Fuse($scope.cabinets, options);
});
问题在于,当我搜索“显示”时,它会返回“屏幕(LCD”,这是机柜的第一项)的ID。如果我搜索“Lampor”,也会发生相同的事情。
根据http://fusejs.io/#searching-by-id
,这不是指定的行为有人可以发现我的错误吗?