2014-10-04 24 views
1

我想使用jquery jcountdown插件,但我遇到了问题。 定时器的起始时间存储在集合中,它是插件初始化所必需的。 我想要做的事,如:如何绑定jquery插件与流星中的数据集

var time = SeqTimestamp.findOne({}).time; 
    $('.countdown').countdown({date: new Date}); 

渲染回调运行一次,并没有看到集合,不是好点了我。 我该怎么做?

回答

1

试着这样做:

Template.whatever.rendered = function() { 
    var self = this; 
    self.autorun(function() { 
    var data = SeqTimestamp.findOne({}); 
    if (data) { 
     self.$('.countdown').countdown({date: data.time}); 
    } 
    }); 
} 
0

我会像这样的东西去:

<template name="whatever"> 
    {{#with theTime}} 
     {{> whatever2}} 
    {{else}} 
     <p>There is no time!</p> 
    {{/with}} 
</template> 
Template.whatever.helpers({ 
    theTime: function(){ 
     return SeqTimestamp.findOne() 
    } 
}) 
<template name="whatever2"> 
    <div class="countdown"></div> 
</template> 
Template.whatever2.rendered = function(){ 
    var theTime = this.data.theTime 
    this.$('.countdown').countdown({date: theTime.time}) 
}