`
ddl1st
  • 浏览: 95783 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Jquery AutoComplete firefox 中文 Ajax (option url or data) Jquery rails 自动完成

阅读更多
application.html
http://docs.jquery.com/Plugins/autocomplete
<!DOCTYPE html>
<html>
<head>
  <title>AotoComplete</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag 'AutoComplete/jquery','AutoComplete/jquery.autocomplete','AutoComplete/jquery.bgiframe.min' %>
  <%= stylesheet_link_tag 'AutoComplete/jquery.autocomplete','AutoComplete/main' %>
  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>


/view/products/_form.html
<script>
  $(document).ready(function(){
    $("#product_name").autocomplete('/products/search',{matchContains: false})}
</script>



products_controller.rb
....
def search
    key_word = params[:q]
   # Product.limit(params[:limit])
    @product_names = Product.connection.select_values("select name from products where name like '%#{key_word}%'")
    respond_to do |format|
      format.html { render :text => @product_names.join("\n")}
    end
  end
...


routes.rb
  resources :products do
    collection do
      get 'search'
    end
  end


其实支持中文,网上也有教程。
在jquery.autocomplete.js的194行左右的
.bind("unautocomplete", function() {
		select.unbind();
		$input.unbind();
		$(input.form).unbind(".autocomplete");  # 下面添加
}).bind("input", function() {
    // @hack by liqt:support for inputing  chinese characters  in firefox
    onChange(0, true);


希望对你有帮助, 我折腾好久。下面有这个autocomplete 的rails 3 demo


推荐阅读http://compdocjos.blogspot.in/2010/11/creating-autocompleting-association.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics