【发布时间】:2020-03-23 14:04:40
【问题描述】:
jQuery-ui 在尝试使用自动完成方法时抛出错误
jquery-ui.min.js:8 Uncaught TypeError: this.source is not a function
at t.<computed>.<computed>._search (jquery-ui.min.js:8)
at t.<computed>.<computed>._search (jquery-ui.min.js:6)
at t.<computed>.<computed>.search (jquery-ui.min.js:8)
at t.<computed>.<computed>.search (jquery-ui.min.js:6)
at t.<computed>.<computed>.<anonymous> (jquery-ui.min.js:8)
at i (jquery-ui.min.js:6)
这是我的代码
$.get('https:/{{pretend there is a proper url here}}/hygiene.php', {op: 'search', business: val}, (res) => {
res = JSON.parse(res);
var businesses = res.map(r => {return r.business})
$('#search-form').autocomplete({
sources: businesses,
appendTo: '#search-form'
})
})
op 和 business 只是 API 工作所需的参数。 API 有效,调用没有任何问题。 该调用返回一个 json 业务字符串(因此是 JSON.parse) 在解析后的数组上调用 map 是只返回商家的名称,因为这是我想在自动完成中显示的内容。
搜索表单是文本输入
<input type='text' id='search-form'/>
我很确定这是 jQuery 而不是我的代码的问题。 使用: https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.jscdn
任何帮助将不胜感激
【问题讨论】:
-
jqueryui.com/autocomplete 应该是来源而不是来源?
标签: javascript jquery ajax jquery-ui