【发布时间】:2014-07-03 21:49:16
【问题描述】:
大家,
我有一个问题在另一个案例中已经发生在我身上,但我提出这个希望我们可以解决它:
jquery(在“渲染”上调用)在不是由 eachloop 生成时运行良好……为什么不能在生成的 html 中运行?
我点击了每个循环生成的图像,没有任何反应
gallery.html
{{#each gallery}}
<div class="superbox-list">
<img src="images/superbox/superbox-thumb-1.jpg" data-img="images/superbox/superbox-full-1.jpg" alt="My first photoshop layer mask on a high end PSD template theme" title="Miller Cine" class="superbox-img">
</div>
{{/each}}
<div class="superbox-list">
<img src="images/superbox/superbox-thumb-1.jpg" data-img="images/superbox/superbox-full-1.jpg" alt="My first photoshop layer mask on a high end PSD template theme" title="Miller Cine" class="superbox-img">
</div>
<div class="superbox-list">
<img src="images/superbox/superbox-thumb-2.jpg" data-img="images/superbox/superbox-full-2.jpg" alt="My first photoshop layer mask on a high end PSD template theme" title="Bridge of Edgen" class="superbox-img">
</div>
gallery.js
Template.gallery.rendered = function(){
$('.superbox').SuperBox();
}
Template.gallery.helpers({
gallery: function(){
return Gallery.find();
}
});
最好的问候, 太棒了
编辑:
我用过这种方法,效果很好,虽然在meteor docs中没有找到defer方法!
_.defer(function () {
$('.superbox').SuperBox();
});
【问题讨论】:
-
你确定你在创建模板时得到了
Gallery中的所有文件吗? -
在你的渲染中不应该是 $('.superbox-list') 而不是 $('.superbox') 吗?
-
Peppe:是的,我在 Gallery 中拥有所有文档,这可能在图 1 中看到。Dave:我认为这不是问题,因为每个 jquery 都运行良好。
标签: javascript jquery meteor