title: Using if statements in jQuery UI Autocomplete
body: <p>Is it possible to set up if statements in the <code>response</code> event and the render item implementation? I have two json files and use data attributes in <code>#searchbox</code> and <code>.searchbar</code> to get the urls. Since the files objects are different, I think I need to use two different responses and markups. Can I set up a switch statment or if statements like the following? I'm getting some kind of undefined error with the code.</p>
  
  <pre><code>Uncaught TypeError: undefined is not a function jquery.js:9597
  </code></pre>
  
  <p>I can see the json file is being returned, but the autocomplete doesn't show up. Any suggestions?</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;input type='text' data-search="jsonfileA" id="searchbox"&gt;
  &lt;input type='text' data-search="jsonfileB" class="searchbar"&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>$( "#searchbox,.searchbar" ).each(function(){
      var search = $(this).data('search');
      $(this).autocomplete({
          source: function( request, response ) {
              $.ajax({
                  url: search,
                  dataType:"json",
                  data:{q:request.term},
                  success: function( data ) {
                   response($.map(data.products, function( item)
                     { 
                      if ($(this).is('#searchbox')) {
                         return {
                          label:item.name,
                          category:item.category
                          }
                     }else {
                         return { 
                         title:item.title,
                         description:item.description
                         }
                      }  
                     });
                   )};
              });
          }
      })
      .data("ui-autocomplete")._renderItem = function(ul, item) {
          var inner_html;
          if ($(this).is('#searchbox')) {  
              inner_html = ''+item.label+'&lt;p&gt;'+item.category+'';
          }
          else {
              inner_html = ''+item.title+'&lt;p&gt;'+item.description+'';
          }
          return $("&lt;li&gt;&lt;/li&gt;")
          .data("item.autocomplete", item)
          .append(inner_html)  
          .appendTo(ul);
      };
  });
  </code></pre>