An event is interfering with Select2 plugin's ajax-retrieved results

前端 未结 1 1825
时光说笑
时光说笑 2021-01-04 10:05

I\'m using Igor Vaynberg\'s Select2 jQuery plugin with the Infinite Scroll with Remote Data option to make an autocomplete search box for my website. The AJAX is working gre

1条回答
  •  走了就别回头了
    2021-01-04 11:01

    Your problem seems like, your result data doesn't have a property named "id". Select2 plugins wants an id field on data and if it has not, it makes option "unselectable". You may give an id function to override this behavior:

    $("#site-search").select2({
       id: function(obj) {
          return obj.slug; // use slug field for id
       },
       ...
    

    0 讨论(0)
提交回复
热议问题