我在Rails应用程序中使用in_place_editor功能。当从Ajax调用返回到已更新数据库对象的服务器时,我想使用:on_complete回调在视图中进行一些额外的更新。不幸的是,我无法得到:on_complete工作。
为了测试,这是我在视图中的内容:
<%= in_place_editor_field "localization", 'sv', {}, {:cols => 11, :on_complete => 'function() {alert(1);}'} %>
不起作用,Javascript控制台说:
Uncaught TypeError: Object function() {alert(1);} has no method 'bind'
这样做:
<%= in_place_editor_field "localization", 'sv', {}, {:cols => 11, :on_complete => 'alert(1);'} %>
结果:
Uncaught TypeError: Object alert(1); has no method 'bind'
有谁可以说这里发生了什么?有没有人使用on_complete?
答案 0 :(得分:0)
如果其他人遇到同样的问题,我做了一个丑陋的解决方法,我正在使用,直到有人提出更好的答案。我修补了scriptaculous controls.js来检查是否有一个已定义的完成后回调以及是否要调用它,如下所示:
wrapUp: function(transport) {
this.leaveEditMode();
// Can't use triggerCallback due to backward compatibility: requires
// binding + direct element
// Beginning of ugly patch:
if(typeof editOnComplete == 'function') {
editOnComplete(this.element);
}
// End of ugly patch
this._boundComplete(transport, this.element);
} });