带有自动完成助手的 jRails

发布于 2024-08-04 15:32:14 字数 313 浏览 3 评论 0原文

我刚刚开始我的项目的新分支,我尝试使用jRails。到目前为止,除了自动完成(尤其是text_field_with_auto_complete)之外,一切都很棒。使自动完成功能再次正常工作的最佳解决方案是什么?

  1. 自己实现整个自动完成(我不太喜欢这个)
  2. 在jquery中重写旧的原型助手,然后将其破解到jRails
  3. 使用一些开箱即用的 jquery 插件

I've just started new branch of my project, where I try to use jRails. As far everything works awesome, except the autocomplete (especially text_field_with_auto_complete). What would be the best solution to make autocomplete working again?

  1. implement whole autocomplete by myself (I don't really like this one)
  2. rewrite the old prototype helper in jquery and then hack it into jRails
  3. use some out of box jquery plugin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说好的呢 2024-08-11 15:32:14

A JRails auto complete plugin is available

http://github.com/evilmarty/jrails_auto_complete

不忘初心 2024-08-11 15:32:14

我会选择选项 3,这是我目前在许多程序中使用的。有一些插件可以实现相同的目标。其中之一是这个,但大多数都可以正常工作。

基本上,您需要做的是创建插件,将其设置为查看文本字段,然后将其设置为某个路由。

这是我手头的一些旧项目的一些代码:

        $("input#send_detail_product_id").autocomplete("products/auto_complete_for_send", {  
        formatItem:formatItem,
                callback:processProduct;

}); 

我使用的插件不接受回调函数,所以我对它进行了一些修改并解决了这个问题。我可以在选择文件后向其发送一个要处理的函数。

在 Rails 控制器上,您可以指定一些逻辑并以 JSON 或通过视图文件返回搜索结果以解决格式问题。就我而言,后者允许我更改产品名称的外观。

通过处理不引人注目的代码的额外好处,这确实很容易完成。

I'd go with option 3, and It's what I currently use in many programs. There are some plugins that achieve the same goal. One of it is this but most of them will work fine.

Basically what you will need to do is create the plugin, set it to look at your text field and then set it to some route.

This is some code from some old project I got at hand:

        $("input#send_detail_product_id").autocomplete("products/auto_complete_for_send", {  
        formatItem:formatItem,
                callback:processProduct;

}); 

The plugin I used didn't accept callback functions, so I hacked it a little and work it out. I can send it a function to process after selecting a file.

On the Rails controller, you can specify some logic and return your search results either as JSON or through a View file for formatting issues. In my case, the latter allows me to change how the product name looks.

It's really quite easy to accomplish with the added bonus of dealing with unobtrusive code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文