I am working with jQuery UI autocomplete plugin and want to display some text if no results are found. I have seen a lot of examples to do this with remote datasets, but I have the source set to a local JSON array. Here is the code I am working with right now, it hides all rows that do not match the selected value. I want to hide all rows and display a 'no entries found' in the text box when a user is typing text that does not match any of the available tags
$( "#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 }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.