2010-10-21 65 views
0

我想用另一個javascript函數調用來擴展button_to_remote的onclick參數,但是我找不到任何答案。 所以我有SG是這樣的:在rails中擴展button_to_remote的onclick參數

button_to_remote('>', :url => {:action => "show_dtree", :id => tree_child.id, :dir1 => dir11, :dir2 => dir12} 

什麼生成以下代碼:

<input onclick="new Ajax.Request('/d_trees/show_dtree/3?dir1=1&amp;dir2=2', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('2e8e2147c344bcee0edf40f8fe6072c12dc928d7')});" type="button" value="&gt;" /> 

我的目的,是要調用一個Foo()函數後,Ajax請求對象實例化:

<input onclick="new Ajax.Request('/d_trees/show_dtree/3?dir1=1&amp;dir2=2', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('2e8e2147c344bcee0edf40f8fe6072c12dc928d7')});foo();" type="button" value="&gt;" /> 

有沒有什麼辦法可以讓我自己生成整個按鈕?

感謝您的幫助!

回答

0

當然,只要將你的函數作爲回調:

button_to_remote '>', 
    :url => { :action => "show_dtree", :id => tree_child.id, :dir1 => dir11, :dir2 => dir12 }, 
    :complete => "foo()" 

這將調用foo Ajax請求完成時。您可以使用任何其他階段,而不是:complete,例如:loading,:success

+0

感謝您的快速回復! – seriakillaz 2010-10-21 20:41:54