我试图将可见的列表视图项目的数量限制为 5。机场变量是一个结构为 jsonp 的字符串。代码如下所示,但我无法弄清楚如何限制列表视图中出现的项目数量。我需要限制这个数字,因为 airports 变量包含数千个项目。谢谢你的帮助!
$( "#destinationListview" ).on( "listviewbeforefilter", function ( e, data ) {
var $ul = $( this ),
$input = $( data.input ),
value = $input.val(),
html = "";
$ul.html( "" );
if ( value && value.length > 3 ) {
$ul.html( "<li></li>" );
$ul.listview( "refresh" );
$.each( airports, function ( i, val ) {
html += "<li class='destination' id='" + val.code + "'>" + val.name + ", " + val.location + "</li>";
});
$ul.html( html );
$ul.listview( "refresh" );
$ul.trigger( "updatelayout");
$(".destination").click(function() {
$( data.input ).val($(this).attr("id"));
$("#destination").val($(this).attr("id"));
$("#destinationListview li").hide();
});
}
});