我正在尝试将我的应用程序与mongodb连接。使用静态数组数据添加帖子可以正常工作。
问题:现在{{post}}下没有显示任何内容。如果我检查我的数据库,则已插入数据。
数据库插入+代码:
db.calposts.insert({ post: "Hello world!", createdAt: new Date() });
WriteResult({ "nInserted" : 1 })
{{#each calposts}}
{{> posts}}
{{/each}}
<template name="posts">
<div class="panel-post" id="post-draggable">
<span>{{post}}</span>
</div>
</template>
if (Meteor.isClient) {
Template.calendar.helpers({
calposts: function () {
return CalPosts.find({});
}
});
}
您是否向客户发布了calpost集合?如果没有,在某个地方的服务器文件夹中你需要使用Meteor.publish()
然后在客户端,运行Meteor.subscribe()
来订阅该出版物。
有关发布和订阅的更多信息,请访问meteor.com上的此页面:
https://www.meteor.com/tutorials/blaze/publish-and-subscribe