我正在开发一个rails web应用程序。在我的一个视图中(在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;
}
此致
答案 0 :(得分:0)
我已经修好了,我会在这里添加解释: 1)删除haml并且只留下de div,将haml放入部分 2)在控制器中添加了一个动作:def dialog stuff = Stuff.find(params [:stuff_id])render:partial => “partial_name”,:locals => {:stuff => stuff},:layout =>假结束
3)在javascript:$(“#div_id”)。empty();
$ .ajax({type:'GET',url:'此案例对话框中的操作的url',缓存:false,数据:{stuff_id:stuff_id},success:function(html){$(“# div_id“+ stuff_id).append(html);}});
希望这可以帮助别人。
此致