【发布时间】:2013-07-15 03:29:24
【问题描述】:
我正在开发一个 Rails 网络应用程序。在我的一个观点中(在 index.html.haml)我有一个 jquery opendialog,我在其中列出了一些东西。 我的问题是我不想在加载索引页面但在 openclick 事件时加载它。 我将提供一些代码。我对 Rails、haml 和 jquery 还很陌生,因此欢迎任何帮助,提前谢谢。
问候。
#...stuff
#dialog creation and loading
.dialog{:id => "codes_#{stuff.id}", :title => t_s(:index, resource_class.to_s.downcase)}
#dialog: haml code with the list loading that is done when the main page is loaded instead on being called at the onclick
#link that opens the dialog
= link_to t_s(:show, resource_class.to_s.downcase), '#', :onclick => "openDialog(#{stuff.id})", :title => t_s(:show, resource_class.to_s.downcase)+ " " +t_s(:index, resource_class.to_s.downcase)
#...stuff
这是一些生成的js:
$(document).ready(function(){
$(".dialog").dialog({ width: 600, height: 400, autoOpen: false, modal: true, show: "blind", hide: "explode"
});
});
function openDialog(id){
$("#codes_"+id).dialog( "open" ); return false;
}
问候
【问题讨论】:
-
你能分享你的javascript吗?
-
问题是您在
document.ready上打开对话框,这就是为什么您的对话框会在文档准备就绪时加载。你想把它移到函数openDialog里面。此外,我会添加编辑帖子的 JS 代码以获得更好的可读性。 -
通过这样做,现在我加载页面时会显示对话框,而不是在我单击按钮之前隐藏
标签: javascript jquery ruby-on-rails ruby haml