- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个 stackoverflow answer尝试为我的 Rails 应用程序实现 Twitter Typeahead,我还尝试实现 Github自述文件,但当我在文本框中输入内容时没有文本建议。
我的 Controller
class PagesController < ApplicationController
def typeahead
@vn = Vn.search_by_name(params[:search])
render json: @vn.results
end
end
我的路线
get 'typeahead/:query' => 'pages#typeahead'
Application.js
//= require twitter/typeahead
//= require twitter/typeahead/bloodhound
assets/javascripts 中的pages_controller.js
var bloodhound = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
// sends ajax request to /typeahead/%QUERY
// where %QUERY is user input
remote: '/typeahead/%QUERY',
limit: 50
});
bloodhound.initialize();
// initialize typeahead widget and hook it up to bloodhound engine
// #typeahead is just a text input
$('.typeahead').typeahead(null, {
displayKey: 'name',
source: bloodhound.ttAdapter()
});
// this is the event that is fired when a user clicks on a suggestion
$('.typeahead').bind('typeahead:selected', function(event, datum, name) {
doSomething(datum.id);
});
我的观点
<%= form_tag(search_path, :method => "get", class: "navbar-form", id: "search-form") do %>
<%= text_field_tag :search, params[:search], class: "form-control padding-search typeahead", placeholder: "Search" %>
<%= button_tag(type: "submit", class: "btn btn-primary padding-search") do %>
<% end %>
最佳答案
在进行了一段时间的故障排除后,这是允许输入提示建议对我起作用的设置。
CoffeeScript
jQuery ->
users = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
#local http://localhost:3000/json/vns.json
remote: {url:'/typeahead/%QUERY'
, wildcard: '%QUERY'
}
})
users.initialize();
$('.typeahead').typeahead(null, {
name: "mysearch"
source: users.ttAdapter()
})
Controller
def typeahead
@vn = Vn.search_by_name(params[:search])
@name = @vn.select('name').map(&:name)
render json: @name
end
//Under Routes
get 'typeahead/:search' => 'pages#typeahead'
//View
<%= form_tag(search_path, :method => "get", class: "navbar-form", id: "search-form" ) do %>
<%= text_field_tag :search, params[:search], class: "form-control typeahead", placeholder: "Search " %>
<%= button_tag(type: "submit", class: "btn btn-primary padding-search") do %>
<i class="fa fa-search 6x"></i>
<% end %>
<% end %>
关于javascript - 使用 pg_search 提前输入 Bloodhound Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34034429/
我正在尝试加载人名的自动完成信息以进行提前输入,然后如果我已经有了结果,则不必再次查询服务器。 例如,如果我搜索一个人的姓名,并且从远程查询中检索该人(以及其他人)的数据,那么当我删除该姓名并搜索姓氏
我正在使用 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 个结果,因为限制是
我是一名优秀的程序员,十分优秀!