使用小胡子模板和实现无限滚动时出现 DOM 异常 8 错误jquery砌体
我正在实现一个深受本教程影响的无尽滚动效果:
http:// railscasts.com/episodes/295-sharing-mustache-templates?view=asciicast
但是,我的做法略有不同,因为我使用的是 Jquery Masonry (http://masonry.desandro.com/demos/adding-items.html) 在前端。
无论如何,当我按如下方式实现时:
jQuery ->
window.endlessScroll = () ->
if $('#products_page').length
new ProductPager
class ProductPager
constructor: ->
$(window).scroll(@check)
check: =>
if @nearBottom()
$(window).unbind('scroll', @check)
$.getJSON($('#products_page').data('json-url'), @render)
nearBottom: =>
$(window).scrollTop() > $(document).height() - $(window).height() - 150
render: (products) =>
boxes= []
$container = $('#products_page')
for product in products
boxes.push Mustache.render $('#mustache_product').html(), product
$container.append(boxes).masonry "appended", boxes
$(window).scroll(@check)
我收到以下错误(Chrome):
未捕获错误:NOT_FOUND_ERR:DOM异常8
我认为问题出在这里:
boxes.push Mustache.render $('#mustache_product').html(), product
因为这将每个模板输出包装在“引号”中,而
["<div>stuff</div>","<div>more stuff</div>"]
不是:
[<div>stuff</div>,<div>more stuff</div>]
但我是对我做错的事情有一点心理障碍......有人愿意帮忙吗?
I am implementing an endless scrolling effect heavily influenced by this tutorial:
http://railscasts.com/episodes/295-sharing-mustache-templates?view=asciicast
However, I am doing it slightly differently because I am using Jquery Masonry (http://masonry.desandro.com/demos/adding-items.html) on the front end.
Anyway, when I implement this as follows:
jQuery ->
window.endlessScroll = () ->
if $('#products_page').length
new ProductPager
class ProductPager
constructor: ->
$(window).scroll(@check)
check: =>
if @nearBottom()
$(window).unbind('scroll', @check)
$.getJSON($('#products_page').data('json-url'), @render)
nearBottom: =>
$(window).scrollTop() > $(document).height() - $(window).height() - 150
render: (products) =>
boxes= []
$container = $('#products_page')
for product in products
boxes.push Mustache.render $('#mustache_product').html(), product
$container.append(boxes).masonry "appended", boxes
$(window).scroll(@check)
I get the following error (Chrome):
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
I think the problem lies here:
boxes.push Mustache.render $('#mustache_product').html(), product
because this wraps each template output in "quotes" i.e.
["<div>stuff</div>","<div>more stuff</div>"]
rather than:
[<div>stuff</div>,<div>more stuff</div>]
But I am having a bit of a mental block about what I am doing wrong.... anyone care to help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过更仔细地遵循 Masonry 网站上的示例来实现此目的,结果是:
I got this to work by following the example on the Masonry website more closely, which resulted in this: