[英]Fuzzy modules Return JSON Array of Matched word?
I'm using fuzzy
module with node but I have long JSON Array contain object. 我正在使用带有节点的
fuzzy
模块,但是我有很长的JSON数组包含对象。 I need matched object whole. 我需要整个匹配的对象。 Like
喜欢
link of module Fuzzy Modules 模块链接模糊模块
var list = [
{rompalu: 'baconing', zibbity: 'simba'}
, {rompalu: 'narwhal' , zibbity: 'mufasa'}
, {rompalu: 'a mighty bear canoe', zibbity: 'saddam hussein'}
];
I have above list of JSON Array and if I pass word narwhal
than It's return only matched words in Array but I need array of matched object. 我上面有JSON Array列表,如果我传递单词
narwhal
,则它仅返回Array中匹配的单词,但我需要匹配对象的数组。 output like : 输出像:
[
{rompalu: 'narwhal' , zibbity: 'mufasa'}
]
There seem to be various options. 似乎有多种选择。
Filter the list manually using fuzzy.test()
: 使用
fuzzy.test()
手动过滤列表:
var results = list.filter(function(obj) { return fuzzy.test('narwhal', obj.rompalu); });
Extract the "originals": 提取“原件”:
var options = { extract: function(el) { return el.rompalu; } }; var results = fuzzy.filter('narwhal', list, options).map(function(r) { return r.original; });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.