- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用“startswith”过滤器来过滤结果。现在,下面的代码获取与结果中任何单独单词匹配的所有内容。因此,当用户输入“ex”时,“example”和“一二示例”都会被过滤掉。如何更改此行为以便仅过滤掉“示例”?
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);
};
};
关于javascript - Twitter 提前输入,Bloodhound 过滤器开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26974309/
我正在尝试加载人名的自动完成信息以进行提前输入,然后如果我已经有了结果,则不必再次查询服务器。 例如,如果我搜索一个人的姓名,并且从远程查询中检索该人(以及其他人)的数据,那么当我删除该姓名并搜索姓氏
我正在使用 Twitter 输入,但发现很难划分 mysql 查询的结果。 我的 json 输出如下所示:{"id":"1","name":"Bravo"} 在当前状态下,typeahead 中的结果
我有一个这样的脚本: $(document).ready(function() { var searchType = $('select[name=searc
这是我的代码: tagsProcessor(){ const suggestions = [{value: 'string1'}, {value: 'string2'}, {value
我使用 Bloodhound 作为提前输入的建议引擎。 问题是当我在 Bloodhound 中使用远程源时。它进行查询并获取结果,但是当我搜索结果时没有返回任何内容。 更具体地说,这段代码工作得很好:
我的印象是在执行远程调用时不需要使用 Bloodhound。我尝试运行此代码: $("#iban2").typeahead({ hint: false, minLength: 4,
我已经使用远程数据源实现了 typeahead.js 和 bloodhound,它基本上按预期工作。但是,我已将 typeahead 上的 minLength 设置为 2,虽然我可以看到 ajax 请
我似乎无法通过远程查询来正确使用 POST。 var creditors = new Bloodhound({ datumTokenizer: function (d) { r
我正在尝试让 twitter typeahead 正常工作,但 type advance 功能不起作用。它不显示自动完成部分。这是 JavaScript 代码。 var films = new Bl
我想使用“startswith”过滤器来过滤结果。现在,下面的代码获取与结果中任何单独单词匹配的所有内容。因此,当用户输入“ex”时,“example”和“一二示例”都会被过滤掉。如何更改此行为以便仅
我正在尝试实现类似于 stackoverflow 标签建议输入字段的功能。在数据库中,我有两个表:一个用于标签,另一个用于标签别名或标签同义词(tagSynonyms)。 当用户键入术语时,搜索引擎应
我正在使用 Bloodhound 从数据库中获取数据,然后使用 twitter 提前输入以显示搜索框下方的选项。 目前,bloodhound 部分正在查找所需的对象,但 typeahead 未显示它们
我正在使用 Twitter typeahead 和 Bloodhound 建议引擎,一切正常。下面是我的代码片段 // instantiate the bloodhound suggestion en
我尝试将下面的代码与 typeahead.js v 0.10 一起使用 // instantiate the bloodhound suggestion engine var numbers = ne
这是我的javascript: $(document).ready(function () { var people = new Bloodhound({
我正在使用 typeahead.js 0.11.1 并尝试对来自远程源的结果进行排序。根据代码,应该可以覆盖 bloodhound 的默认排序功能。但是我的排序函数从未被调用过。识别函数的计数相同。
我是第一次使用 twitter typeahead.js。我首先从一个简单的本地数组开始,然后让它开始工作。 作为下一步,我现在正尝试使其与 .json 文件一起使用。尽管我尝试了几种选择,但我无法使
我将 Typeahead(带有默认建议)与 Bloodhound 一起使用,到目前为止一切正常。但是,当我尝试动态更改建议的值时遇到了一些问题。 例如,当我选择其中一个元素时,我有一系列可用的建议,例
如何提前输入以提交数据。 这里是jsfiddle上的相关代码http://jsfiddle.net/6W3Qu/2/ . 代码副本: var numbers = new Bloodhound({ da
我正在使用 Typeahead/Bloodhoud 进行公司搜索,但自动完成部分没有显示足够的匹配项。 ------------ 搜索------------ 我应该至少看到 5 个结果,因为限制是
我是一名优秀的程序员,十分优秀!