English 中文(简体)
未显示数据
原标题:Jquery autocomplete not show data

I am using the autocomplete jquery json but it is not showing the result. There is following code I am using.

$(function() {

    $( "#course" ).autocomplete({
        source: function( request, response ) {
            $.ajax({
                url: "ajax.php",
                dataType: "json",
                data: {
                    style: "full",
                    maxRows: 20,
                    name_startsWith: request.term
                },
                success: function( data ) {
                    response( $.map( data.geonames, function( item ) {
                        return {
                            Id: item.Id + (item.FirstName ? ", " + item.LastName : "") + ", " + item.Email,
                            value: item.Id
                        }
                    }));
                }
            });
        },
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.label :
                "Nothing selected, input was " + this.value);
        },
        open: function() {
            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
        },
        close: function() {
            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
        }
    });
});
</script>

Ajax案卷采用了这一格式。

      [{"Email":"[email protected]","FirstName":"Sobha","Id":12333,"LastName":"Marati"}]
问题回答

我认为,你必须用<代码>label <>/code>和<代码> 价值的特性建造一个json物体:

{[label:  text , value:  val ]...}

由于对菜单项目的缺省制成法是:

_renderItem: function( ul, item) {
    return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( $( "<a></a>" ).text( item.label ) )
        .appendTo( ul );
}

如果你想提供另一个json物体作为数据来源,那么你必须提供新的<代码>_renderItem方法,并建造带有新特性的菜单。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...