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

时间:2017-06-13 09:27:53

标签: javascript meteor coffeescript

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

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

  
      
  1. publish.coffee
  2.   
Meteor.publish 'reportPage', ->
     userId = @userId
       reportpage = Dealers.find('owner': userId)
     if Dealers
       return reportPage
  @ready()
  
      
  1. reportpage.js
  2.   
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
  2.   
<template name="reportpage">
    {{> tabular table=TabularTables.Dealers class="table table-striped table-bordered table-condensed"}}
</template>

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

2 个答案:

答案 0 :(得分:0)

尝试使用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

答案 1 :(得分:0)

我这样解决了:

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