gpt4 book ai didi

jquery - 使用rails4-autocomplete时,未捕获的类型错误: this.源不是函数

转载 作者:行者123 更新时间:2023-12-01 01:42:50 25 4
gpt4 key购买 nike

我目前正在尝试在搜索字段上设置自动完成功能。我正在使用rails4-autocomplete gem。我已阅读此处的文档:https://github.com/peterwillcn/rails4-autocomplete 并遵循了使其工作的所有步骤,并且它确实有效。我开始在搜索框中输入内容,然后得到了预期的结果。

我的下一步是实现一键搜索功能。当我单击自动完成建议之一时,我希望网站转到该项目的相应页面。我使用了 http://www.yoniweisbrod.com/autocomplete-magic-with-rails/ 上名为 Autocomplete Magic with Rails 的页面上的建议

基本上,您添加一个事件 Hook ,在选择某个项目时提交搜索按钮。

$( document ).ready(function() {
$('.search-query').bind('railsAutocomplete.select', function(event, data {
$('.search-me').trigger('click')
});
});

当我实现它时,这种方法是有效的,就像有时当我单击我希望它进入页面的项目时,有时它不会去任何地方。它只是用项目信息填充文本框,但不提交。在这些情况下,我收到一个 jQuery 错误,内容如下:

 Uncaught TypeError: this.source is not a function - autocomplete.self-3befc48aba87cead090cfd014562b2771a662ac6d2c8197b24c08b2d9f3d9f2d.js?body=1:440 

刷新页面修复了这个问题,这让我认为我的 javascript 没有按正确的顺序加载。因此,我实现了 jQuery Turbolinks gem,以确保我的 jQuery 事件始终加载而无需刷新页面。这没有帮助。

出于信息目的,我的 jQuery 如下所示:

$( "#username" ).autocomplete({ html: true });

将 html 选项设置为 true 允许我在搜索结果中呈现 html。

我一直在谷歌搜索,但到目前为止还没有运气。有什么想法吗?谢谢!

最佳答案

我相信您没有将源代码添加到自动完成中:

var data = ['one', 'two'];
$("#your-id").autocomplete({
data
});

关于jquery - 使用rails4-autocomplete时,未捕获的类型错误: this.源不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34489217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com