jQuery的autocomplete完成搜索下拉选择

$( "#car_companyName" ).autocomplete({
        source: function(request, response) {
            var term = request.term;
            if ( term in companyCache ) {
                response( $.map( companyCache[ term ], function( item ) {
                    return {
                        name:item.name,
                        value:item.name,
                        id:item.id
                    }
                }));
                return;
            }
            $.ajax({
                url: contextPath+"/Company/getByCarName",
                dataType: "json",
                data:{
                    searchDbInforItem: request.term
                },
                success: function( data ) {
                    companyCache[ term ] = data;
                    response( $.map( data, function( item ) {
                        return {
                            name:item.name,
                            value:item.name,
                            id:item.id
                        }
                    }));
                }
            });
        },
        minLength: 1,
        select: function( event, ui ) {
            $("#car_companyName").val(ui.item.name);
            $("#car_companyNumber").val(ui.item.id);
        }
    });

你可能感兴趣的:(jQuery的autocomplete完成搜索下拉选择)