【发布时间】:2015-11-17 08:18:55
【问题描述】:
我在我的 Meteor 应用程序中做错了,但根本无法找出它是什么。我没有在 UI 中收到任何数据。这是代码。
lib/common.js
Data = new Meteor.Collection('data2');
'data2' 是我创建的一个集合,在 mongo shell 中响应良好
服务器/app.js
Meteor.publish("Data", function() {
return Data.find({});
});
客户端/app.js
Meteor.subscribe("Data");
客户端/helpers.js
Template.home.helpers({
results: function(){
return Data.find();
}
});
我什至尝试在 find() 中指定两列-field1, 2 无济于事。
客户端/home.html
<template name="home">
<table class="table table-striped tablesorter z-depth-5">
<thead>
<tr>
<th width="15%">field1</th>
<th width="15%">field2</th>
</tr>
</thead>
<tbody>
{{#each results}}
<tr>
<td>{{field1}}</td>
<td>{{field2}}</td>
</tr>
{{/each}}
</tbody>
</table>
检查结果 -
Data.find().fetch()
[]
【问题讨论】:
-
只是为了笑,
Meteor.publish('myData',...)和Meteor.subscribe('myData')以排除多次使用名称Data的问题 -
将 'Data' var 更改为 'myData' - 仍然没有骰子。
-
Meteor.Collection现在是Mongo.Collection,尽管这不是您的问题。当您说“检查结果”时,您的意思是您在 Web 控制台中运行了它? -
我看不出你所做的有什么明显的错误。尝试将 autopublish 包放回去,看看数据是否显示。然后,您可以将问题缩小到您的出版物或订阅。
-
@DavidWeldon - 是的 - 在网络控制台中。