jQuery UI autocomplete- no results message

前端 未结 4 565
一个人的身影
一个人的身影 2020-12-02 01:59

I\'m trying to have a \"No Results\" message appear in the dropdown menu if there are no results. So for instance, if I type in \"ABCD\" into the text field, and there is n

4条回答
  •  感动是毒
    2020-12-02 02:02

    Modify the function like this to check for length of data.

    success: function (data) {
        if(!data.length){
            var result = [
                {
                    label: 'No matches found', 
                    value: response.term
                }
            ];
            response(result);
        }
        else{
            // normal response
            response($.map(data, function (item) {
                return {
                    label: item.CompanyName + " (" + item.SymbolName + ")",
                    value: item.CompanyName
                }
            }));
        }
    }
    

提交回复
热议问题