jQuery UI Autocomplete JSON example data returned
What does the
data.geonames in
response( $.map( data.entities, function( item ) mean?
I am using a web method an an ASPX page to return the data (a List<object> collection) but don't know what I need to do to specify the 'geonames' part, or whatever would be relevant for my application.
My c# code is as follow:
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public List<TheEntity> SearchEntitesJSON(string title)
- {
- Manager mng = new Manager();
- List<TheEntity> entList = mng.SearchEntites(title);
- return entList;
- }
My jquery in the markup is virutally the same as in the autocomplete JSON datasource example except for I have replaced the url with my method above and changed dataType to JSON instead of JSONP. My script is as follows:
- <script type="text/javascript">
- $(function() {
- function log( message ) {
- $( "<div>" ).text( message ).prependTo( "#log" );
- $( "#log" ).scrollTop( 0 );
- }
- $( "#city" ).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: "Post.aspx/SearchEntitesJSON",
- dataType: "json",
- data: {
- featureClass: "P",
- style: "full",
- maxRows: 12,
- name_startsWith: request.term
- },
- success: function( data ) {
- response( $.map( data.entities, function( item ) {
- return {
- label: item.Title,
- 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>