使用 Meteor.publish 过滤用户访问数据

Filter data for user access with Meteor.publish

我需要帮助:我无法使 (Meteor.publish) 过滤页面数据并应用用户(所有者)添加的许可。

现在我向您展示我用 Coffescript 编写的代码(publish.coffee 和使用包 (aldeed:tabular - https://atmospherejs.com/aldeed/tabular)

的 DataTable JS
  1. publish.coffee
Meteor.publish 'reportPage', ->
     userId = @userId
       reportpage = Dealers.find('owner': userId)
     if Dealers
       return reportPage
  @ready()
  1. reportpage.js
TabularTables ={};

Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);

TabularTables.Dealers = new Tabular.Table({
  name: "Dealers",
  collection: Dealers,
  columns:[
     {data: "name", title: "Name"},
     {data: "p_iva", title: "Partita IVA"},
  ]
}, { 
    waitOn: function() {
        return [
            Meteor.subscribe("reportPage"),
        ]
    },
    path: "/reportPage"
});
  1. reportpage.html
<template name="reportpage">
    {{> tabular table=TabularTables.Dealers class="table table-striped table-bordered table-condensed"}}
</template>

我该如何解决? 请帮我! :(

尝试使用 selector 过滤表格使用的结果。

TabularTables.Dealers = new Tabular.Table({
  name: "Dealers",
  collection: Dealers,
  columns:[
    {data: "name", title: "Name"},
    {data: "p_iva", title: "Partita IVA"},
  ], 
  selector: function (userId) {
    if (!!userId) {
      return {owner: userId}
    }
  },
}

有关详细信息,请参阅 Displaying Only Part of a Collection's Data Set

我是这样解决的:

Template.reportpage.helpers({
  selector () {
    if (!!Meteor.userId()) {
      return { owner: Meteor.userId() };
    }
  },
});