我有许多帖子想要在走马灯中展示。为了使用走马灯,我使用 OwlCarousel 。
<div class="owl-carousel" id="featured-carousel">
{{#each featuredPosts}}
<div>
<h2>
{{postTitle}}
</h2>
</div>
{{/each}}
</div>
我这样调用我的轮播:
Template.featuredCarousel.rendered = function(){
$('#featured-carousel').owlCarousel({
loop:true,
autoplay:true,
autoplayTimeout:3000,
items:1,
smartSpeed:1080,
padding:80
});
this.rendered = true;
};
我得到的结果是,Owl实际上认为我只有一个项目可以在走马灯中显示,这些项目是多个div。显然,在模板的#each部分完成或数据到达之前,Template.featuredCarousel.rendered内部的函数被调用。
我该如何使实例化轮播的函数仅在完全渲染包括所有数据的模板后才被调用?
非常感谢您的帮助。
附言:我使用iron-router进行路由,代码如下:
Router.map(function(){
this.route('home', {
path: '/',
waitOn: function(){
return Meteor.subscribe('featured');
},
data: function(){
return {featuredPosts: Featured.find({})};
}
});
});
P.P.S.:我也尝试使用加载模板,但这并没有帮助。