jQueryUI autocomplete - when no results are returned

前端 未结 3 819
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 11:19

I\'m wondering how one can catch and add a custom handler when empty results are returned from the server when using jQueryUI autocomplete.

There seem to be a few questio

3条回答
  •  逝去的感伤
    2021-02-19 11:47

    It is easy to handle with response option

    $( 'input.Srch' ).autocomplete({
        minLength: 3,
        .......
        response: function(event, ui) {
            if (!ui.content.length) {
                    var noResult = { value:"",label:"No results found" };
                    ui.content.push(noResult);
            }
        }
    });
    

    Here is my screenshot:

提交回复
热议问题