来自Collection not rendering的Meteor Full Calendar事件数组

时间:2015-02-05 15:45:21

标签: javascript arrays mongodb meteor fullcalendar

我遇到了Meteor和FullCalendar程序包的问题(rzymek:fullcalendar),如果我直接定义事件数组,它会显示事件,但如果我从我的Collection中获取它们,它甚至不会填充数组虽然Find方法在控制台中工作并向我显示我的事件(事件数组在控制台中显示为空)。 我没有删除自动发布或不安全的软件包:这是一个基本的测试。

main.js文件:

if (Meteor.isServer) {
    Meteor.startup(function() {
        if (Meetings.find().count() === 0) {
            Meetings.insert({
                title: 'All Day Event',
                start: '2015-02-06'
            });
        }
    });
}

if (Meteor.isClient) {
/* //this array of events shows if uncommented
        events = [
            {
            title: 'reuni',
            start: '2015-02-06'
            }
            ]*/
    Template.calendar.helpers({
        options: function() {
            return {
                events: events
            }
        }
    });
}

我的collection.js文件(在lib文件夹中):

Meetings = new Mongo.Collection('meetings');

events = Meetings.find({}, {fields: {_id:0} }).fetch();  /*This will only show an empty array and not the events array that I fetch*/

1 个答案:

答案 0 :(得分:0)

设置集合后立即设置事件。由于您只是将其保存为数组,因此将来不会发生任何查询。

尝试类似

的内容
if (Meteor.isClient) {
  Template.calendar.helpers({
    options: function() {
      var events = [];
      Meetings.find().forEach(function(m){
        events.push( 
           // build object with needed properties here
        );
      });
      return {
          events: events;
      }
    }
  });
}

基本上你需要帮助程序中的find函数,或者在该帮助程序的计算内部调用。将它留在全局定义区域之外将删除它的所有重新活动。