jQuery Autocomplete .data(“autocomplete”) is undefined

前端 未结 6 1637
盖世英雄少女心
盖世英雄少女心 2021-02-03 20:58

When I try to implement auto-complete using the code below I get an error stating:

.data(\"autocomplete\") is undefined

How ever if I remove th

6条回答
  •  轮回少年
    2021-02-03 21:18

    I found the solution!

    Somepeople think that "ui-autocomplete" is wrong, so they use "autocomplete" or "uiAutocomplete", but that is wrong. Actually, "ui-autocomplete" is the right way to do this.

    I have the same issue you have, and I find with a friend the problem of this code. Instead:

    .data('ui-autocomplete')._renderItem = function (ul, item) {
           if (!_.include(self.idArr, item.id)) {
                return $('
  • ').data('ui-autocomplete-item', item).append('' + item.name + '').appendTo(ul); } };

    Use:

    ._renderItem = function (ul, item) {
          if (!_.include(self.idArr, item.id)) {
             return $('
  • ').data('ui-autocomplete-item', item).append('' + item.name + '').appendTo(ul); } };

    I think combobox and autocomplete returns a data('ui-autocomplete'), so if you type .data('ui-autocomplete') you're doing something like:

    .data('ui-autocomplete').data('ui-autocomplete')
    

    What's wrong....well, actually I don't know why this don't work and why without this works, but trust me, delete .data('ui-autocomplete') and be happy!

提交回复
热议问题