我有一个观点。在这个视图中,我想用AJAX 4分页。我有两个人在工作。当我添加第三个(执行与其他方法相同的方法)时,前两个停止工作。要粘贴一些代码供你们理解。
使用AJAX的2个分页的视图:
<div id="ofertas"><%= render "ofertas_ajax" %></div>
这会通过集合项和遗嘱分页链接呈现正常循环的部分。一切都很好。
另一个正在发挥作用的是:<div id="historico"><%= render "historico_ajax" %></div>
这就像上面的另一个一样呈现部分。
我的application.js为这两个:
$(document).on("click","#ofertas .pagination a",function(e){
e.preventDefault();
$.getScript(this.href);
});
$(document).on("click","#historico .pagination a", function(e){
e.preventDefault();
$.getScript(this.href);
});
我的home.js.erb
,因为所有这些div都在home.html.erb
视图
$("#ofertas").html("<%= escape_javascript(render("ofertas_ajax")) %>");
$("#historico").html("<%= escape_javascript(render("historico_ajax")) %>");
好的 - 所以这很好用。至少测试它我没有看到任何问题,它使用AJAX正确分页。
我为第3个分页添加了这个div:
<div id="candidaturass"><%= render "candidaturaspag" %></div>
再次呈现具有正常循环的正常部分,并且正确的将分页链接
我在application.js
$(document).on("click","#candidaturass .pagination a",function(e){
e.preventDefault();
$.getScript(this.href);
});
再次与其他人相似。当然我在home.js.erb
文件中添加了这个:
$("#candidaturass").html("<%= escape_javascript(render("candidaturaspag")) %>");
现在所有的分页都不起作用。在我添加这一行之后。我不知何故认为我的home.js.erb
文件不应该是这样的:
$("#ofertas").html("<%= escape_javascript(render("ofertas_ajax")) %>");
$("#historico").html("<%= escape_javascript(render("historico_ajax")) %>");
$("#candidaturass").html("<%= escape_javascript(render("candidaturaspag")) %>");
然而我又真的不知道为什么它不起作用。如果我的文件编码正确。
有人可以帮忙吗?
答案 0 :(得分:1)
试试这个...在js.erb中渲染时要小心...引号应该注意: -
尝试遵循: -
##adding single quotes
$("#ofertas").html("<%= escape_javascript(render('ofertas_ajax')) %>");
$("#historico").html("<%= escape_javascript(render('historico_ajax')) %>");
$("#candidaturass").html("<%= escape_javascript(render('candidaturaspag')) %>");
以上部分仅在它们是reqular partials时才有效,否则你必须明确指定users / _partial_name或其他你想要的东西