【问题标题】:creating a twitter like auto suggest search box in rails在rails中创建一个类似自动建议搜索框的twitter
【发布时间】:2012-09-27 08:08:55
【问题描述】:

请那些知道如何创建类似自动建议搜索框的 twitter 或 facebook 的人?我已经尝试实现了一段时间...这是我从enter link description here 获得的一些代码。

 <div class="search_index">


 <div id = "testsearch">
 <%=render :partial => 'search'%> // partial where the updated search elements will appear from 
 </div>

<%=form_tag(search_path,:method=>'get',:remote=>true) do%>

   <%=text_field_tag :search%>
   <%= submit_tag "search" ,:name=>nil%>

<%end%>

<%= set_focus_to_id 'search' %>  // I have a helper "set_focus_to_id"



<script> // small javascript file :)

 document.observe("dom:loaded", function() {   // ensures the page is loaded first
 new Form.Element.Observer(                    // Observes the text_field_tag every 2     seconds
  'search',
   2,
   respondToChange                         //refrences the function in the Layout      
   )                                         // on a change in search calls   respondToChange
  });

  </script>

  </div>

在我有的标签上

 <script>
 function respondToChange() {
 $('search').up('form').submit()            // The ".up finds the form in the DOM"
 };
 </script>

代码似乎不起作用,甚至没有响应

请问有人知道如何以更有效的方式实现此功能

我真的需要这方面的帮助

【问题讨论】:

标签: jquery twitter autocomplete ruby-on-rails-3.2 autosuggest


【解决方案1】:

一个不错的选择是使用预先存在的脚本:

  1. http://tweet.seaofclouds.com/
  2. http://jquery.malsup.com/twitter/

他们创造了自己的,它有一些值得考虑的功能。甚至使用。

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2016-06-13
    • 1970-01-01
    相关资源
    最近更新 更多