我正在使用rails web應用程序。在我的一個觀點(在index.html.haml)我有一個jQuery的opendialog,我列出了幾件事情。 我的問題是,我不想加載索引頁面時加載,但在openclick事件。 我會提供一些代碼。我對rails,haml和jquery仍然很陌生,所以任何幫助都會受到歡迎,這要提前感謝。使用haml在rails上與ruby異步加載jquery opendialog
問候。
#...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嗎? – vee
問題在於你打開'document.ready'上的對話框,這就是你的對話框在文檔準備就緒時加載的原因。你想在那個函數'openDialog'中移動它。此外,我會添加編輯帖子的JS代碼,以提高可讀性。 – vee
通過這樣做,當我加載頁面時,對話框顯示出來,而不是隱藏,直到我點擊按鈕 – TheMadCapLaughs27