page.insert_html 未正确渲染部分

发布于 2024-09-03 14:22:37 字数 790 浏览 2 评论 0原文

以下内容位于文本字段中。

= 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 技术交流群。

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

发布评论

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

评论(1

人间☆小暴躁 2024-09-10 14:22:37

如果您指定要更新的元素,则假定您的操作将返回 html(不是 rjs/javascript),这将替换指定元素的内容。

因此,如果您需要替换 :suggestions 的内容,只需在控制器中渲染部分即可:

render :partial => 'suggestions'

但是如果您需要向此元素添加内容而不是替换,请删除 :update => :suggestions 来自您的视图代码:

= f.text_field :title, :size => 50, :onchange => remote_function(:url => {:action => :display_question_search_results})

并将控制器代码保留为原样:

page.insert_html :bottom, 'suggestions', :partial => '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:

render :partial => 'suggestions'

But if you need to add contents to this element, not to replace, remove :update => :suggestions from your view code:

= f.text_field :title, :size => 50, :onchange => remote_function(:url => {:action => :display_question_search_results})

And leave controller code as is:

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