簡體   English   中英

jQuery UI自動完成顯示(如果沒有結果)

[英]jQuery UI autocomplete display if no results

我正在使用jQuery UI自動完成插件,並且如果未找到結果,則希望顯示一些文本。 我已經看到了很多使用遠程數據集執行此操作的示例,但是我將源設置為本地JSON數組。 這是我現在正在使用的代碼,它隱藏了與所選值不匹配的所有行。 當用戶鍵入與任何可用標簽都不匹配的文本時,我想隱藏所有行並在文本框中顯示“找不到任何條目”

$( "#archiveVendor" ).autocomplete({
    source: availableTags,
    select: function(event, ui){
        var emptyRow = '<tr class="emptyArchive"><td class="approved_content">---</td><td>---</td><td>---</td><td class="payment_status">---</td></tr>';
        $('.archive_inner .emptyArchive').remove();
        $('.archive_inner tr').show().filter(function(index){
            var tds = $(this).children('td');
            if($(tds).length == 4){
                if($(tds[1]).text() == '---'){
                    return false;
                }
                var title = $(tds[0]).attr('title');
                return title === ui.item.value ? false : true;
            }
        }).hide();

        if($('.archive_approved tr:visible').length == 1){
            $('.archive_approved tbody').append(emptyRow);
        }
        if($('.archive_denied tr:visible').length == 1){
            $('.archive_denied tbody').append(emptyRow);
        }
    }
});

也許您可以將ui.item.value與數組進行比較?

if(jQuery.inArray(ui.item.value, json_array) == -1) { add text to right field and hide() other fields }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM