如何将jquery插件与Meteor中的集合数据绑定

时间:2014-10-04 12:32:17

标签: jquery meteor

我想使用jquery jcountdown插件,但我遇到了问题。 计时器的开始时间存储在集合中,并且插件初始化是必需的。 我想做点什么:

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

渲染回调运行一次,并没有看到对我来说不好的集合。 我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

尝试这样做:

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

答案 1 :(得分: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})
}