每个循环流星内部的jQuery都不起作用 [英] jQuery inside each loop meteor not works

查看:81
本文介绍了每个循环流星内部的jQuery都不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是每个人,

我有一个问题已经发生在我的另一个案例中,但我提出这个希望我们可以解决它:

i have a problem that has already happened to me in another case, but I present this hoping that we can solve it:

jquery(调用呈现)在不是由eachloop生成时运行良好...为什么不在生成的html中工作?

The jquery (called on "rendered") works well when it is not generated by eachloop ... why not work in generated html?

我点击eachloop生成的图像,没有任何反应

i click on an image generated by eachloop and nothing happens

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();
    }
});

例如,
图片1 图片2

最好的问候,
ty

best regards, ty

编辑:

我用这种方式工作,虽然在流星文档中没有找到延迟方法!

I used this way and it worked, although not find the method defer in meteor docs!

_.defer(function () {
  $('.superbox').SuperBox();
});


推荐答案

您的问题可能 首次渲染图库时,数据不存在。您可以通过使用iron-router的 waitOn 等待订阅来解决这个问题(如果您使用的是铁路由器),但这只能解决其中的文档问题。页面加载数据库。任何新文件也不会是超级盒子。因此,解决方法是为每个Gallery行设置一个特定的模板。
您的每一个都变为:

Your issue is probably that the data isn't there when your gallery is first rendered. You can fix that by waiting on the subscription using iron-router's waitOn (if you're using iron-router) but that only solves the problem of the documents that are in the database on page load. Any new documents wouldn't be "superBox'd" either. So the way around that is to have a specific template for each Gallery row. Your each becomes:

{{#each gallery}}
    {{> galley_row }}
{{/each}}

你添加一个新模板:

<template name="gallery_row">
    <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>
</template>

然后每当渲染新模板时(#each循环的每次迭代):

Then whenever your new template is rendered (each iteration of the #each loop):

Template.galley_row.rendered = function () {
    $('.superbox').SuperBox();
});

这篇关于每个循环流星内部的jQuery都不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆