在可嵌入javascript视图中使用mislav_will_paginate
Using mislav_will_paginate in embeddable javascript view
尝试创建一个视图,可以在嵌入(通过js)在另一个文档时提供一组分页结果。这代替了使用iframe。父文档中的嵌入代码如下所示:
<script type="text/javascript" src="http://MYWEBSITE/search?query=MYPARAMETERS&embed=true&per_page=20"/>
响应此操作的视图(embed.html.erb)如下所示:
(function(){
document.write('<div id="df_search_results">')
<% @results.each do |result| %>
document.write('<a href="<%= result.url %>" rel="lightbox[aj]" title="<%= result.title %>"><img src="<%= result.other_url %>" width="100" height="100" /></a>')
<% end %>
<% if @hits > @results.size %>
document.write(<%= will_paginate @results %>)
<% end %>
document.write('</div>')
})()
当排除will_paginate标记时,它可以正常工作。当包含will_paginate标记时,它无法完全呈现,并且不会在日志中记录任何错误。
问题出在这一行:
document.write(<%= will_paginate @results %>)
will_paginate
方法的输出将被插入到脚本中,但没有作为传递给write()
方法的字符串正确引用。你需要转义。
escape_javascript
方法:
document.write('<%= j will_paginate(@results) %>')
(注意单引号)
如果你不使用Rails,你可以在这里复制它的源代码
相关文章:
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- Will my'新对象'在套接字断开连接时被垃圾收集
- window.location.reload(true) will clear HttpSession?
- Will var result = function() { //doSomething };if (result !=
- Will'http:url'适用于所有浏览器和设备
- 无限卷轴不适用于Will Paginate和Masonry
- Will.abort()理论上中止了我的javascript函数
- javascript:will window.location发出任何警告
- CSS3 + Javascript - Will -ms-transition:不透明15易进易出;仅在IE 10中工作
- JavaScript setTimeout will not die.
- Will The Mark of The Web始终确保IE运行本地HTML文件
- Will Underscore.js defaults()会设置一个定义在原型上的属性
- what will be the value of 'this'?