0

我想讓自動完成使用jQuery UI的工作,但它似乎並沒有被觸發。使用coffescript的Rails jQuery自動完成

hashtag.js.coffee被加載到application.js中。有沒有在控制檯或者

hashtag.js.coffee

$('.swag_text_field').autocomplete 
source: ['foo', 'food', 'four'] 

視圖

<%= form_tag hashtags_path, class: "search-form", remote: true do %> 
      <div class="input-prepend input-append"> 
      <span class="add-on swag">#</span> 

      <%= text_field_tag :hashtag, nil, class: "span4 swag_text_field", id:"appendedPrependedInput" %> 

      <%= submit_tag "VS!", class: "btn add-on-right swag_button" %> 
      <% end %> 

回答

3

原來咖啡腳本被引發的錯誤是空白敏感。

jQuery -> 
     $('.swag_text_field').autocomplete 
      source: ['foo', 'food', 'four'] 
+0

就像一個魔術,upvoted爲它。但爲什麼是這樣。你能解釋一下嗎?我只是在我的代碼中創建了1個縮進/標籤並且它能夠工作;( – ImranNaqvi

+0

答案意味着您應該在自動完成方法之後縮進一行標籤空間 – ImranNaqvi