title: Twitter's typeahead example / dynamic query
body: <p>I am searching for an example for <a href="https://github.com/twitter/typeahead.js" rel="nofollow">twitter's typeahead</a>.</p>
  
  <p>I want to get the data with a function, should I use remote?
  The returned from the server data would be a Json (not simply an array).
  From those I want to display only the field e.g. <code>name</code>.</p>
  
  <p>Upon selection of the correct <code>name</code> I want to run another function that e.g. alerts the <code>id</code> and the <code>description</code> (fields) of that object. Probably with <a href="https://github.com/twitter/typeahead.js#custom-events" rel="nofollow"><code>typeahead:autocompleted</code></a> event binder ?</p>
  
  <p><strong>Update/ sample:</strong></p>
  
  <p>The <code>Dajaxice.async.get_closest_events()</code> bellow sends 3 parameters to the internal server (lat,lng, query). Query is the value the users has written. It returns an array (<code>venuesNames</code>) which is going to be displayed in the dropdown.</p>
  
  <pre><code>$( "#locationQueryInput" ).typeahead({
      remote:{
          replace: function (query ) {
              //alert($("locationQueryInput").val());
              Dajaxice.async.get_closest_events( 
                  (function(data){                                            
                      venuesNames = []
                      venuesDetails = []
                      for (var i = 0; i &lt; data.fVenues.length; i++) {
                          venuesNames.push(data.fVenues[i].name)
                          venuesDetails[ data.fVenues[i].name ] = {
                                                  'id' : data.fVenues[i].id,
                                                  'lat' : data.fVenues[i].lat,
                                                  'lng' : data.fVenues[i].lng,
                                                  'address' :data.fVenues[i].address,
                                                  'city' :data.fVenues[i].city,
                          }
                      }
                      return venuesNames
                  }), 
                  {'lat' : new_marker_latlng.lat, 'lng' : new_marker_latlng.lng, 'query' : query }  
              );
          }
  
  
      }
  
  }).bind('typeahead:selected', function(obj,datum){
  // do stuff upon completion
  ...
  }
  </code></pre>