page.insert_html 未正确渲染部分
以下内容位于文本字段中。
= f.text_field :title, :size => 50, :onchange => remote_function(:update => :suggestions, :url => {:action => :display_question_search_results})
以下内容位于 display_questions_search_results.rjs 中。
page.insert_html :bottom, 'suggestions', :partial => 'suggestions'
每当用户键入时,我想在数据库中搜索与文本字段中的关键字匹配的任何元组。然后,显示这些结果。但是,目前,_suggestions.haml 仅包含“建议!!”一词。
但是,看到的不是“建议!!”在 suggestions
div 标签中,我得到:
try { Element.insert("suggestions", { bottom: "suggestions!!" }); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.insert(\"suggestions\", { bottom: \"suggestions!!\" });'); throw e }
我一直在试图找出这样做的原因,但我发现之前提出的问题似乎比我正在做的更复杂......
The following is in the text_field.
= f.text_field :title, :size => 50, :onchange => remote_function(:update => :suggestions, :url => {:action => :display_question_search_results})
The following is in display_questions_search_results.rjs.
page.insert_html :bottom, 'suggestions', :partial => 'suggestions'
Whenever the user types, I'd like to search the database for any tuples that match the keywords in the text field. Then, display those results. But, at the moment, _suggestions.haml only contains the word "suggestions!!".
But, instead of seeing "suggestions!!" in the suggestions
div tag, I get:
try { Element.insert("suggestions", { bottom: "suggestions!!" }); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.insert(\"suggestions\", { bottom: \"suggestions!!\" });'); throw e }
I've been trying to find out why this is being done, but the previously asked questions I found seem more complicated than what I'm doing...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您指定要更新的元素,则假定您的操作将返回 html(不是 rjs/javascript),这将替换指定元素的内容。
因此,如果您需要替换
:suggestions
的内容,只需在控制器中渲染部分即可:但是如果您需要向此元素添加内容而不是替换,请删除
:update => :suggestions
来自您的视图代码:并将控制器代码保留为原样:
If you specify element to update, it is assumed that your action will return html (not rjs/javascript), that will replace contents of specified element.
So, if you need to replace contents of
:suggestions
, just render partial in your controller:But if you need to add contents to this element, not to replace, remove
:update => :suggestions
from your view code:And leave controller code as is: