gpt4 book ai didi

javascript - meteor /砖石 : wait until all templates are rendered

转载 作者:行者123 更新时间:2023-12-03 10:00:50 25 4
gpt4 key购买 nike

这个问题有点类似于Meteor : wait until all templates are rendered ,但我再次问它,因为它实际上似乎没有答案,我会解释原因。

有以下模板代码

<template name="home">
<div>
<ul>
{{#each this}}
{{> item}}
{{/each}}is ready
</ul>
</div>
</template>

<template name="item">
<li><img src="{{amz-picture-url}}"></li>
</template>

我想在所有“item”渲染后执行代码。它们有很多,我尝试了很多方法,例如 onRendered、将iron-router 的 waitOn 添加到 home 模板、jQuery 的 imagesLoaded 函数来尝试等待图像...

上一个问题中接受的答案使用iron-router来等待数据准备好,但是除了数据准备好之外,我确实需要渲染子模板,我需要它来调用Masonry。

在这个 Meteor 用例中是否有一种可靠的方法来使用 Mansory,或者我应该完全改变我正在使用的方法,因为在这种情况下无法在正确的时刻调用 Mansory?

最佳答案

您可以添加onload事件处理程序到您的 <img> s 计算调用次数。一旦达到项目数量,您就完成了。

类似于:

<template name="item">
<li><img src="{{amz-picture-url}}" onload="countImages()"></li>
</template>

然后在js中:

var imageCounter = 0;
function countImages() {
if(++imageCounter == this.length) {
// Do whatever you need
}
}

关于javascript - meteor /砖石 : wait until all templates are rendered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30607705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com