首页 文章

具有FS.Collection的流星反应表

提问于
浏览
1

我正在努力实现基于FS.Collection对象的反应表 . 我已经尝试了aldeed / meteor-tabular和aslagle / reactive-table,但两者都失败了,因为集合似乎不存在 . 但是,如果我在不使用反应式表包的情况下订阅和检索集合中的字段,那么数据显示就好了 . 我错过了什么?两个包都无法工作,这不是巧合......

这是我使用aslagle / reactive-table包的实现...

//template
  <template name="documentTable">
  {{#if Template.subscriptionsReady}}
    {{> reactiveTable settings=settings}}
  {{else}}
    {{> spinner}}
  {{/if}}
  {{#if currentUser}}
    {{> fileUpload}}
  {{/if}}
</template>

//documents js
Template.documents.onCreated( () => {
  p_id = FlowRouter.current().params.id;
  Template.instance().subscribe('documents', p_id);
});

Template.documents.helpers({
  documents: function () {
    return Documents.find();
  },

  settings: function () {
    return {
      collection: documents,
      showFilter: false,
      rowsPerPage: 5,
      showNavigation: auto,
      showRowCount: true,
      fields: ['_id','userId','propertyId','uploadedAt']
    };
  }
});

//collection definition 
if (Meteor.isServer) {
  var docStore = new FS.Store.S3("documents", {
    region: "eu-west-1",
    accessKeyId: (Meteor.isServer && !process.env.AWS_ACCESS_KEY_ID ? Meteor.settings.AWSAccessKeyId : null),
    secretAccessKey: (Meteor.isServer && !process.env.AWS_SECRET_ACCESS_KEY ? Meteor.settings.AWSSecretAccessKey : null),
    bucket: Meteor.isServer && process.env.AWS_S3_BUCKET || Meteor.settings.AWSBucket,
    folder: "documents"
  });

  Documents = new FS.Collection("Documents", {
    stores: [docStore],
    filter: {
      allow: {
        contentTypes: ['application/pdf']
      }
    }
  });
}
// end server

if (Meteor.isClient) {
  var docStore = new FS.Store.S3("documents");

  Documents = new FS.Collection("Documents", {
    stores: [docStore],
    filter: {
      allow: {
        contentTypes: ['application/pdf']
      }
    }
  });
}
// end client

// allow rules
Documents.allow({
  insert: function(userId) {
    // only allow insert from signed in user
    return userId != null;
  },
  update: function(userId) {
    // only allow update from signed in uesr
    return userId != null;
  },
  download: function() {
    return true;
  },
});

在反应表情况下,我得到的错误是该参数不是Mongo.Collection,游标或数组的实例,而使用meteor-tabular时它无法启动,因为遇到ReferenceError并指出Documents不是定义 .

有人对此有何看法?

1 回答

  • 0

    我正在使用带有mongo的aslagle / reactive-table,使用pub / sub模型;我不知道你的新FS是什么?那个mongo系列?

    当我使用反应表时,我有类似的东西......

    //on the server
    Documents = new Mongo.Collection('documents');
    
    //on the client js
    Documents = new Mongo.Collection('documents');
    
    Template.documents.helpers({
       settings: function () {
          return {
          collection: Documents.find(),
          rowsPerPage: 5,
          showFilter: false,
          showNavigation: auto,
          showRowCount: true,
          fields: [
             {key: '_id',
              label: 'ID' },
             {key: 'userId',
              label: 'User#' },
             {key: 'propertyId',
              label: 'Property#' },
             {key: 'uploadedAt',
              label: 'Uploaded' },
             ]
          };
       }
    });
    
    //on the client html file
    {{> reactiveTable class="table table-bordered table-hover" settings=settings}}
    

相关问题