开发者

How to access the selectedItem property in JQuery UI autocomplete?

I'm using a JQuery UI autocomplete to retrieve a list of suggested localities from the server. Localities hava an id, name and location. The开发者_如何转开发 autocomplete shows the name of the locality in the dropdown list and in text box when one locality is selected.

This is easy achieved passing the success method to the autocomplete:

success : function(data) {
  if (data.responseHeader.status == 0) {
    response($.map(data.response.docs, function(item){
      var mappedData = {
    label : item.name,
    value : item.name,
    id: item.id,
    location: item.location
  }
  return mappedData;
    }));
  }
}

When you select an item from the autocomplete, the mappedData is stored in the selectedItem attribute of the autocomplete. This can be seen using firebug. I need to access this attribute to be able to get the location of the selected locality so that I'm able to perform proximity searches.

Thanks in advance!


You can add a select to your autocomplete:

select: function(event, ui)
{
    var selectedLocation = ui.item.location;
},
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜