2013-07-16 18 views
0

我正在使用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; 
} 

問候

+0

你能分享你的javascript嗎? – vee

+0

問題在於你打開'document.ready'上的對話框,這就是你的對話框在文檔準備就緒時加載的原因。你想在那個函數'openDialog'中移動它。此外,我會添加編輯帖子的JS代碼,以提高可讀性。 – vee

+0

通過這樣做,當我加載頁面時,對話框顯示出來,而不是隱藏,直到我點擊按鈕 – TheMadCapLaughs27

回答

0

已經修好了我自己,我會在這裏補充說明: 1)取出HAML和只剩德div,將haml放在一個局部區域中 2)在控制器中添加一個動作:def dialog stuff = Stuff.find(params [:stuff_id])render:partial =>「partial_name」,:locals => {:stuff => stuff},:layout => false end

3)在javascript:$(「#div_id」)。empty(); ({type:'GET',url:'在這種情況下對話框中動作的url',cache:false,data:{stuff_id:stuff_id},success:function(html){$(「 #div_id「+ stuff_id).append(html);}});

希望這可以幫助別人。

Regards