2010-10-21 50 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