Rails:使用observe_field返回空白选择选项?

发布于 2024-09-24 01:23:43 字数 433 浏览 0 评论 0原文

我的应用程序中有一个observe_field调用,如下所示:

  = observe_field "marketSelect", :update => "merchantSelect", :with => "id", :url => { :controller => "markets", :action => "get_merchants" }

该代码在我的市场控制器中激活以下操作:

@merchants = @market.merchants.sort_by { |merchants| merchants.name }

该代码返回与所选市场关联的每个商家的列表,并将它们填充到另一个选择列表中。

如何与商家一起插入空的“选择商家...”?

谢谢

I have an observe_field call in my app like this:

  = observe_field "marketSelect", :update => "merchantSelect", :with => "id", :url => { :controller => "markets", :action => "get_merchants" }

That code activates the following action in my markets controller:

@merchants = @market.merchants.sort_by { |merchants| merchants.name }

That code returns a list of every merchant associated with the selected market, and populates them into another selection list.

How can I insert an empty "Select merchant..." along with the merchants?

Thank you

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

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

发布评论

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

评论(2

乱世争霸 2024-10-01 01:23:43

嗯..我在 http://joshhuckabee.com/rails-observe-field 找到了这个-function-and

observe_field 'text_field_id', 
    {:function => "(value == '') ? 
        $('email_preview').innerHTML = 
             '<em>not entered yet</em>' :
        $('email_preview').innerHTML = 
             value.replace(/\\n/g, '<br/>');", 
      :on => 'keyup'}

作者用prototype做到了这一点。他添加了一个小片段,用 HTML 换行符替换回车符,并且在未输入文本或字段被清除时设置默认值。

Hmm.. I found this at http://joshhuckabee.com/rails-observe-field-function-and

observe_field 'text_field_id', 
    {:function => "(value == '') ? 
        $('email_preview').innerHTML = 
             '<em>not entered yet</em>' :
        $('email_preview').innerHTML = 
             value.replace(/\\n/g, '<br/>');", 
      :on => 'keyup'}

The author did this with prototype. He had added a little snippet that will replace carriage returns with HTML line breaks and also set a default value if no text is entered or the field gets cleared out.

淡水深流 2024-10-01 01:23:43

谢谢你的建议。我最终只是构建了一个直接的 javascript 解决方案。

Thanks for the suggestion. I ended up just building a straight javascript solution.

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