2015-11-11 51 views
0

products.js.coffee如何從自動完成重定向到(jQuery的)

$ -> 
    $('#titles').autocomplete(
    source: gon.titles 
    minLength: 2).click -> 
    $(this).autocomplete 'search' 
    return 
    return 

index.html.erb

... 
<div class="ui-widget"> 
    <input id="titles" /> 
</div> 
... 

在源我從所有產品稱號(我用過吉恩寶石)。我想從自動完成中選擇產品並重定向到所選產品。

感謝您的諮詢!

回答

0

我的解決方案products.js.coffee

doSearch = (term, location) -> 
    window.location.href = 'products?utf8=✓&search=' + term + '&commit=Search' 
    return 

$(document).ready -> 
    $('#titles').autocomplete 
    minLength: 1 
    source: gon.titles 
    select: (event, ui) -> 
     doSearch ui.item.label, ui.item.city 
     return 
    return