简体   繁体   English

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

[英]jquery autocomplete this.source is not a function error

I've implemented autocomplete on an input field, but the box does not show up and firebug returns "this.source is not a function".我已经在输入字段上实现了自动完成,但该框没有出现,并且萤火虫返回“this.source 不是函数”。 I've used autocomplete on other fields of the same page without any problems.我在同一页面的其他字段上使用了自动完成,没有任何问题。 (two textarea's). (两个 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()

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});

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.如果您尝试使用来自http://www.devbridge.com/projects/autocomplete/jquery/#demo 的自动完成功能,它现在会与 jQuery UI 中的自动完成方法发生冲突。 I had the same problem and later noticed that I could just use the jQuery UI implementation.我遇到了同样的问题,后来注意到我可以只使用 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

If you use it with jQuery UI library it also has plugin named autocomplete .如果您将它与 jQuery UI 库一起使用,它还具有名为autocomplete插件。 In this case you can use plugin alias devbridgeAutocomplete :在这种情况下,您可以使用插件别名devbridgeAutocomplete

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

This solve the problem with jQuery UI collision这解决了 jQuery UI 冲突的问题

As Shelton stated, the version from devbridge.com (1.1.3) collides with jQuery UI (1.8.4).正如谢尔顿所说,来自 devbridge.com (1.1.3) 的版本与 jQuery UI (1.8.4) 发生冲突。 Got it working by making sure the devbridge version loads after jQuery UI's version.通过确保在 jQuery UI 版本之后加载 devbridge 版本来让它工作。

Had similar problem for tagedit/autocomplete. tagedit/自动完成有类似的问题。 It seems you also want to disable the autocomplete.看来您还想禁用自动完成功能。 Setting the source to false avoids these errors.将源设置为 false 可避免这些错误。

Solution:解决方案:

options.autocompleteOptions.source = false;

Search at the end of jquery.autocomplete.js the 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 devbridgeAutocomplete instead of autocomplete or any name by changing this $.fn.devbridgeAutocomplete所以..您可以通过更改此$.fn.devbridgeAutocomplete来使用devbridgeAutocomplete而不是自动完成或任何名称

in my case I had a second import of jquery which I didn't realize.就我而言,我没有意识到第二次导入 jquery。 Something like:就像是:

<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后导入自动完成脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM