我正在使用lodash重新创建受数据表智能搜索启发的“智能”搜索。 如此处所述-https://stackoverflow.com/a/39989001/4050261
下面的代码是https://stackoverflow.com/a/37023510/4050261的灵感
var text = 'Bhavesh Hingad';
var values = ['Bha', 'Hin'];
console.log(_.some(values, (el) => _.includes(text, el)), text, values);
// Expecting True
var text = 'Bhavesh Jain';
var values = ['Bha', 'Hin'];
console.log(_.some(values, (el) => _.includes(text, el)), text, values);
// Expecting False
<script src="https://cdn.jsdelivr.net/lodash/4.11.2/lodash.min.js"></script>
当前,代码正在执行基于OR
的过滤,我正在寻找基于AND
的过滤
答案 0 :(得分:0)
找到了答案。感谢Google :)。需要使用every
代替some
var text = 'Bhavesh Hingad';
var values = ['Bha', 'Hin'];
console.log(_.every(values, (el) => _.includes(text, el)), text, values);
// Expecting True
var text = 'Bhavesh Jain';
var values = ['Bha', 'Hin'];
console.log(_.every(values, (el) => _.includes(text, el)), text, values);
// Expecting False
<script src="https://cdn.jsdelivr.net/lodash/4.11.2/lodash.min.js"></script>