Rails 3.1 - 需要显示带有字段内容的 JS 弹出窗口 - 可以轻松完成吗?
我所显示的表格的屏幕空间有限,因此我显示了描述字段的截断视图:
<td><%= simple_format car.description.truncate(200, :separator => ' ') %></td>
我需要将鼠标悬停或单击事件来生成一个简单的弹出窗口(一个“警报”、一个“工具提示”、“对话框”等)显示 car.description 字段的完整内容。
我是公认的 JS 菜鸟。我看到的所有 JS-Rails 教程/信息都集中在不引人注目的 JS 上,主要处理 AJAX/远程服务器交互。我没有看到任何有助于理解如何在视图中的丰富 JS UI 功能中使用 Rails 应用程序中的数据的内容。我看到了一个工具提示 gem,但是使用该 gem,工具提示内容是静态生成的,并且工具提示保存在自己的表中。它无法根据从数据库中提取的字段动态生成工具提示。
有没有一些非常非常简单的方法让 JS 弹出 Rails 字段中保存的文本?
I have limited screen space for a table that I'm displaying, so I'm showing a truncated view of a description field:
<td><%= simple_format car.description.truncate(200, :separator => ' ') %></td>
I need a mouse over or click event to generate a simple pop up window (an "alert", a "tool tip", a "dialog", etc.) displaying the full contents of the car.description field.
I'm an admitted JS rookie. All the JS-Rails tutorials/information that I'm seeing are focused on unobtrusive JS, dealing mostly with AJAX/remote server interactions. I'm not seeing anything that helps understand how you can use data from your Rails application in rich JS UI features within your views. I saw a tool tip gem, but with that gem, tool tip content is statically generated, and tool tips are held in their own table. It provides no way to generate a tool tip on the fly, based on a field pulled from the database.
Is there some very, very simple way to have JS pop-up the text held in a Rails field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我创建了一个虚拟 Rails 项目@ https://github.com/rahul/SO_9347471。我使用了 twitter 的 bootstrap @ http://twitter.github.com/bootstrap/index 提供的模态库.html。
下载该项目,然后
我为每辆车创建了一个模态 div,当引导 javascript 库加载时,它将所有此类 div 转换为引导模态(并且隐藏它们,等待用户单击截断的文本)
========================================
看看
http://jqueryui.com/demos/dialog/
然后
http://twitter.github.com/bootstrap/javascript.html#modals
它们包含易于理解的文档来帮助您开始吧。如果您需要更多说明,请告诉我。
I created a dummy rails project @ https://github.com/rahul/SO_9347471. I used the modal library provided by twitter's bootstrap @ http://twitter.github.com/bootstrap/index.html.
Download that project and,
I created a modal div for each car and when the bootstrap javascript library loads, it converts all such divs into bootstrap modals (and hides them, waiting for a user to click on the truncated text)
====================================
Take a look a
http://jqueryui.com/demos/dialog/
and then
http://twitter.github.com/bootstrap/javascript.html#modals
They contain an easy to follow documentation to help you get started. Let me know if you need more clarification.
我想我会发布我的最终解决方案。我能够严格使用 HTML 和 CSS 来解决这个问题 - 不需要 JS。每当光标移动到截断的描述上时,就会立即出现一个弹出窗口,然后随着鼠标移开而消失。
这是我使用的 HTML:
然后我添加了以下 CSS:
I thought I would post my final solution. I was able to solve this using strictly HTML and CSS - no JS required. Whenever the cursor roles over the truncated description, a pop-up window will immediately apear and then disappear as the mouse it moved away.
Here is the HTML I used:
Then I added the following CSS: