Materialize CSS autocomplete with JQuery UI error Uncaught TypeError: this.source is not a function

Materialize CSS autocomplete with JQuery UI error Uncaught TypeError: this.source is not a function

我正在使用 Materialize CSS 库,其中有一个选项可以制作 autocomplete dropdown(您可以在页面末尾找到)

如果我尝试使用它,当我输入内容时它会显示此错误

Uncaught TypeError: this.source is not a function
at t.(anonymous function).(anonymous function)._search (http://localhost/imgup/js/jquery-ui.min.js:2345:101)
at t.(anonymous function).(anonymous function)._search (http://localhost/imgup/js/jquery-ui.min.js:139:77)
at t.(anonymous function).(anonymous function).search (http://localhost/imgup/js/jquery-ui.min.js:2341:175)
at t.(anonymous function).(anonymous function).search (http://localhost/imgup/js/jquery-ui.min.js:139:77)
at t.(anonymous function).(anonymous function). (http://localhost/imgup/js/jquery-ui.min.js:2337:74)
at i (http://localhost/imgup/js/jquery-ui.min.js:302:62)

我搜索了这个问题,但没有找到任何有用的答案

这是我的 Materialise CSS - HTML 代码

<input type="text" id="autocomplete-input" class="autocomplete">

这是 javascript 用于自动完成

$('input.autocomplete').autocomplete({
data: {
"Apple": null,
"Microsoft": null,
"Google": 'http://placehold.it/250x250'
},
limit: 20, // The max amount of results that can be shown at once. Default: Infinity.
onAutocomplete: function(val) {
// Callback function when value is autcompleted.
},
minLength: 1, // The minimum length of the input for the autocomplete to start. Default: 1.
});

并且有一些屏幕截图表明我在错误日志下方出现错误

控制台错误:

正在发生的文件错误 - 1:

正在发生的文件错误 - 2:

正在发生的文件错误 - 3:

正在发生的文件错误 - 4:

正在发生的文件错误 - 5:

我该如何解决这个问题?请帮助我

您使用的 jQuery/Materialize 是哪个版本?看看这支笔在哪里工作:

http://codepen.io/anon/pen/RpBRjJ

您是否将 jQuery 代码包装在 $(document).ready() 之类的代码中?

如果您正在加载 jquery-ui 那么错误

this.source is not a function"

也会发生。

在那种情况下,您不能使用 jquery $('input.autocomplete').autocomplete(),但需要使用 M.Autocomplete 替代调用。