1

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

这是我使用 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 的实例、游标或数组的错误,而使用流星表时它无法启动,因为它遇到 ReferenceError 并声明 Documents 不是定义。

有人对此有任何想法吗?

4

1 回答 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}}
于 2016-09-17T22:36:59.950 回答