簡體   English   中英

Rails:帶有:with選項的link_to_remote原型助手

[英]Rails: link_to_remote prototype helper with :with option

我正在嘗試使用Prototype獲取下拉列表的當前值,並使用:with像這樣傳遞它

<%= link_to_remote "today", :update => "choices",
    :url => { :action => "check_availability" } , 
    :with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'",
    :loading => "spinner.show(); $('submit').disable();",
    :complete   => "spinner.hide(); $('submit').enable();" %>

但是,這不能按預期方式工作。 我無法訪問控制器中的參數,因為link_to_remote幫助器正在發送這樣的參數:

Parameters: {"succ"=>"function () {\n    return this + 1;\n}", "action"=>"check_availability", "round"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "ceil"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "floor"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "times"=>"function (iterator, context) {\n    $R(0, this, true).each(iterator, context);\n    return this;\n}", "toPaddedString"=>"function (length, radix) {\n    var string = this.toString(radix || 10);\n    return \"0\".times(length - string.length) + string;\n}", "toColorPart"=>"function () {\n    return this.toPaddedString(2, 16);\n}", "abs"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "controller"=>"main"}

我要去哪里錯了? 有一個更好的方法嗎?

嘗試這個

<%= link_to_remote "today", :update => "choices",
    :url => { :action => "check_availability" } , 
    :with => "'practitioner='+$F('practitioner')+&'clinic='+$F('clinic')+&'when=today'",
    :loading => "spinner.show(); $('submit').disable();",
    :complete   => "spinner.hide(); $('submit').enable();" %>

這是區別

:with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'",

應該更改為

:with => "'practitioner='+$F('practitioner')**+**&'clinic='+$F('clinic')**+**&'when=today'",

參考: http : //firstruby.wordpress.com/2008/11/03/remote_function-or-link_to_remote-with-multiple-parameters-in-ruby-on-rails/

謝謝,薩利爾。

您建議的解決方案也存在一些問題(引發Javascript語法錯誤)。 我猜它與我的報價問題相同,我無法弄清楚。 但是該解決方案可以徹底解決該問題,並且可以順利運行:

:with => "$H({ practitioner: $F('practitioner'), clinic: $F('clinic'), 
         when: 'today' }).toQueryString()"

參考: http : //www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterious-parameter

我建議這樣做:

<%= link_to_remote "today", :update => "choices",
  :url => { :action => "check_availability" } , 
  :with => "'practitioner='+$('practitioner').value +'&clinic='+$('clinic').value+'&when=today'",
  :loading => "spinner.show(); $('submit').disable();",
  :complete   => "spinner.hide(); $('submit').enable();" %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM