Javascript jquery 自动完成 this.source 不是函数错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3308935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:06:15  来源:igfitidea点击:

jquery autocomplete this.source is not a function error

javascriptjqueryjquery-ui

提问by Jaap Rood

I've implemented autocomplete on an input field, but the box does not show up and firebug returns "this.source is not a function". I've used autocomplete on other fields of the same page without any problems. (two textarea's).

我已经在输入字段上实现了自动完成,但该框没有出现,并且萤火虫返回“this.source 不是函数”。我在同一页面的其他字段上使用了自动完成,没有任何问题。(两个 textarea 的)。

I'm using the following code to debug, same effect if I run from script file or Firebug command line.

我正在使用以下代码进行调试,如果我从脚本文件或 Firebug 命令行运行,效果相同。

var fakedata = ['test1','test2','test3','test4','ietsanders'];
$("#omschrijving").autocomplete(fakedata);

running jquery 1.4.2 and jquery ui 1.8.2, both minified versions.

运行 jquery 1.4.2 和 jquery ui 1.8.2,都是缩小版本。

Does anyone have an idea how autocomplete works fine on the textareas but causes this malfunctioning on inputs?

有没有人知道自动完成如何在 textarea 上正常工作,但会导致输入出现故障?

Error & Stack trace:

错误和堆栈跟踪:

this.source is not a function
http://facturatie.autodealers.nl/dev/resources/js/jquery-ui-1.8.2.custom.min.js
Line 570
close(Object { name="a"})jquery....min.js (regel 570)
close(Object { name="a"}, Object { name="c"})jquery....min.js (regel 570)
response()

回答by Jaap Rood

Answer is that the first parameter of the autocomplete should be an object containing the "source" property. This works

答案是自动完成的第一个参数应该是一个包含“源”属性的对象。这有效

var fakedata = ['test1','test2','test3','test4','ietsanders'];
$("#omschrijving").autocomplete({source:fakedata});

回答by B Shelton

If you were trying to use autocomplete from http://www.devbridge.com/projects/autocomplete/jquery/#demo, it now collides with the autocomplete method in jQuery UI. I had the same problem and later noticed that I could just use the jQuery UI implementation.

如果您尝试使用来自http://www.devbridge.com/projects/autocomplete/jquery/#demo 的自动完成功能,它现在会与 jQuery UI 中的自动完成方法发生冲突。我遇到了同样的问题,后来注意到我可以只使用 jQuery UI 实现。

(NOTE: It appears that this page's documentation is wrong: http://docs.jquery.com/Plugins/Autocomplete#Setup)

(注意:这个页面的文档似乎是错误的:http: //docs.jquery.com/Plugins/Autocomplete#Setup

回答by Jose gonzalez

If you use it with jQuery UI library it also has plugin named autocomplete. In this case you can use plugin alias devbridgeAutocomplete:

如果您将它与 jQuery UI 库一起使用,它还具有名为autocomplete. 在这种情况下,您可以使用插件别名devbridgeAutocomplete

$('.autocomplete').devbridgeAutocomplete({ ... });

This solve the problem with jQuery UI collision

这解决了 jQuery UI 冲突的问题

回答by Ivan Mercedes

As Shelton stated, the version from devbridge.com (1.1.3) collides with jQuery UI (1.8.4). Got it working by making sure the devbridge version loads after jQuery UI's version.

正如谢尔顿所说,来自 devbridge.com (1.1.3) 的版本与 jQuery UI (1.8.4) 冲突。通过确保在 jQuery UI 版本之后加载 devbridge 版本来让它工作。

回答by j88

Had similar problem for tagedit/autocomplete. It seems you also want to disable the autocomplete. Setting the source to false avoids these errors.

tagedit/自动完成有类似的问题。看来您还想禁用自动完成功能。将源设置为 false 可避免这些错误。

Solution:

解决方案:

options.autocompleteOptions.source = false;

回答by Hermann Diener

Search at the end of jquery.autocomplete.jsthe following section:

jquery.autocomplete.js的末尾搜索以下部分:

Create chainable jQuery plugin:

创建可链接的 jQuery 插件:

$.fn.devbridgeAutocomplete = function (options, args) {....

This devbridgeAutocomplete is an alternative plugin to access to the same functionality using this lines:

此 devbridgeAutocomplete 是使用以下行访问相同功能的替代插件:

if (!$.fn.autocomplete) {
    $.fn.autocomplete = $.fn.devbridgeAutocomplete;
}

So.. you can use devbridgeAutocompleteinstead of autocompleteor any name by changing this $.fn.devbridgeAutocomplete

所以..你可以通过改变这个devbridgeAutocomplete来代替自动完成或任何名称$.fn.devbridgeAutocomplete

回答by Samsky

in my case I had a second import of jquery which I didn't realize. Something like:

就我而言,我没有意识到第二次导入 jquery。就像是:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.2.27/jquery.autocomplete.min.js"></script> 

// More code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script>

So be sure to import the autocomplete script after you initialized jquery.

所以一定要在初始化jquery后导入自动完成脚本。