推特打字,寻血猎犬滤镜开始
Twitter typeahead, Bloodhound filter startswith
我想用'startswith'过滤器过滤结果。现在,下面的代码会获取与结果中任何单独单词匹配的所有内容。因此,当用户键入"ex"时,"示例"和"一两个示例"都会被过滤掉。如何更改此行为,以便仅过滤掉"示例"?
var repos;
repos = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
name: 'terms',
url: 'search.php',
}
});
repos.initialize();
$('input.typeahead').typeahead(null, {
name: 'repos',
source: repos.ttAdapter(),
templates: {
empty: '<div class="empty-message">No matches.</div>',
suggestion: Handlebars.compile([
'<div class="term-box" id="{{id}}">',
'<p class="term">{{termname}}</p>',
'</div>'
].join(''))
}
});
只需像这样更改子字符串函数:
var substringMatcher = function (strs) {
return function findMatches(q, cb) { // an array that will be populated with substring matches
var matches = [];
// regex used to determine if a string contains the substring `q`
//var substrRegex = new RegExp(q, 'i');
// we use starts with instead of substring
var substrRegex = new RegExp('^' + q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function (i, str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
相关文章:
- 可以在这里为背景图像设置滤镜吗
- 使用 GSAP 对模糊滤镜进行动画处理
- 在没有滤镜的情况下模糊背景
- Kineticjs 将 Mask 滤镜应用于图层
- 将特殊效果应用于所选滤镜
- 角度滤镜不打印空格
- HTML5 画布对比度滤镜
- 如何在IE中将灰度和反转效果与SVG滤镜相结合
- 角度滤镜和 NgAnimate 冲突
- 根据滤镜的值有条件地添加 ng-animate 指令
- D3:将滤镜作为背景添加到SVG元素
- 如何为图像添加滤镜(模糊)
- 推特打字,寻血猎犬滤镜开始
- 从一个画布复制带有滤镜的图像并粘贴到另一个画布
- Array.滤镜打破狩猎印花
- Kinetijs:应用滤镜后阴影模糊不起作用
- HTML5画布不能应用sw滤镜
- 选择滤镜不适用于cellTemplate, angular ui-grid
- 如何为对象制作滤镜
- 用CanvasRenderingContext2D滤镜保存画布