Kendo UI autocomplete retrieve id on select

Utsab picture Utsab · Jul 30, 2013 · Viewed 8.2k times · Source

Here is my code:

 $(document).ready(function() {
                    var autocomplete = $("#customers").kendoAutoComplete({
                        minLength: 1,
                        dataTextField: "VenueName", change:onChange,

                        select: onSelect,
                        template: '<img src=\"${data.Thumbnail}" alt=\"${data.VenueName}\" />' +
                                  '<h4>${ data.VenueName }</h4>' +
                                  '<p>${ data.VenueAddress }</p>',
                        dataSource: {
                            transport: {
                                read:{
                                    dataType: "jsonp",
                                    url: "load.php?dbsources=listvenues"
                                }
                            }
                        },
                        height: 370,
                    }).data("kendoAutoComplete");


                });

And the data source will look like this:

([{"VenueID":"84","ID":"10421","VenueName":"Utivs Venue","VenueAddress":"72/74 Meehan Street" ,"Thumbnail":"10421-logo-sd-175x195-img.png"},{"VenueID":"85","ID":"10429","VenueName":"Richards place","VenueAddress":"2 Cross Street" ,"Thumbnail":"10429-logo-sd-175x195-img.png"},{"VenueID":"86","ID":"10437","VenueName":"Lyndzs House of Mandominion","VenueAddress":"80 Chesterfield Parade" ,"Thumbnail":"10437-logo-sd-175x195-img.png"} ])

How do I get VenueID and ID from datasource for further operation on select. I want to save VenueID and ID in a hidden field when a value is selected from autocomplete.

Many Thanks in advance.

Answer

user1856096 picture user1856096 · Apr 29, 2014
select: function (ev) {

                var dataItem = this.dataItem(ev.item.index());
                alert(dataItem.VenueID);
                alert(dataItem.ID);
            }