简体   繁体   English

this.source 不是函数。 jquery-ui 错误

[英]this.source is not a function. Error with jquery-ui

jQuery-ui is throwing an error when attempting to use the autocomplete method 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)

Here is my code这是我的代码

$.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 and business are simply paramters required from the API to work. op 和 business 只是 API 工作所需的参数。 The API works and there's nothing wrong with the call. API 有效,调用没有任何问题。 The call returns a json string of businesses (hence the JSON.parse) Calling map on the parsed array is to return only the names of the businesses as that is what I would like to display in the autocomplete.该调用返回一个 json 业务字符串(因此是 JSON.parse)在已解析的数组上调用映射是仅返回业务名称,因为这是我想在自动完成中显示的内容。

search form is a text input搜索表单是文本输入

<input type='text' id='search-form'/>

Am pretty sure it is an issue with jQuery and not my code.我很确定这是 jQuery 的问题,而不是我的代码。 Using: https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js cdn使用: https: //cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js cdn

Any help would be appreciated任何帮助,将不胜感激

Should be source not sources应该是源不是源

https://codepen.io/ernerock/pen/ByoqVo https://codepen.io/ernerock/pen/ByoqVo

$(function() {
    var availableTags = [
      "Rock",
      "Rap",
      "Trova",
      "Blues",
      "Country",
      "Folk",
      "Jass",
      "POP",
      "Electronic"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });

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

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