我想在旋转木马里面显示一些帖子.对于旋转木马,我使用OwlCarousel.
<div class="owl-carousel" id="featured-carousel">
{{#each featuredPosts}}
<div>
<h2>
{{postTitle}}
</h2>
</div>
{{/each}}
</div>
Run Code Online (Sandbox Code Playgroud)
我这样叫我的旋转木马:
Template.featuredCarousel.rendered = function(){
$('#featured-carousel').owlCarousel({
loop:true,
autoplay:true,
autoplayTimeout:3000,
items:1,
smartSpeed:1080,
padding:80
});
this.rendered = true;
};
Run Code Online (Sandbox Code Playgroud)
我得到的结果是Owl基本上认为我只有一个项目要在转盘中显示多个div.显然,在模板的#each-part完成之前或数据到达之前调用Template.featuredCarousel.rendered中的函数.
如何在完全呈现模板(包括所有数据)后调用实例化轮播的功能?
非常感谢您的帮助.
PS:我使用铁路由器进行路由,如下所示:
Router.map(function(){
this.route('home', {
path: '/',
waitOn: function(){
return Meteor.subscribe('featured');
},
data: function(){
return {featuredPosts: Featured.find({})};
}
});
});
Run Code Online (Sandbox Code Playgroud)
PPS:我也尝试过使用加载模板,但这也无济于事.