【发布时间】:2017-11-14 23:52:15
【问题描述】:
我需要帮助:我无法让 (Meteor.publish) 过滤页面数据并应用用户(所有者)添加的许可。
现在我向您展示我在 Coffescript 中编写的代码(publish.coffee 和使用包的 DataTable 的 JS (aldeed:tabular - https://atmospherejs.com/aldeed/tabular)
- publish.coffee
Meteor.publish 'reportPage', ->
userId = @userId
reportpage = Dealers.find('owner': userId)
if Dealers
return reportPage
@ready()
- 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"
});
- reportpage.html
<template name="reportpage">
{{> tabular table=TabularTables.Dealers class="table table-striped table-bordered table-condensed"}}
</template>
我该如何解决? 请帮我! :(
【问题讨论】:
-
我不太了解 CoffeeScript,但 .find 接受 JSON 对象。因此,在发布方法中,Dealers.find({'owner': userId})。否则,看起来您的 HTML 在订阅数据之前就已渲染,请尝试在路由上订阅数据或在渲染表之前检查是否订阅了数据。
-
我试图应用这个 Meteor.publish "reportpage", -> Dealers.find { owner: this.userId }, 但是所有用户的数据总是出现:( 在我的情况下它只是必要的显示登录用户(所有者)的输入数据
-
从您的应用程序中删除自动发布包。
-
已删除,但无法正常工作:(
-
我发现这是我的情况,但我不知道该放在哪里:{userId: Meteor.userId ()} 看这里:github.com/aldeed/meteor-tabular/issues/13“你会通过 { userId: Meteor.userId()} 作为表上的选择器属性。”
标签: javascript meteor coffeescript