gpt4 book ai didi

javascript - 如何在 Meteor JS 客户端主视图中显示 Mongodb 集合?

转载 作者:太空宇宙 更新时间:2023-11-04 02:10:59 25 4
gpt4 key购买 nike

我是 MeteorJS 新手。我尝试使用以下代码在客户端 View 中显示 MongoDB 集合。

client/main.js

Resolutions = new Mongo.Collection('resolutions');

Template.body.helpers({
resolutions : function(){
return Resolutions.find();
}
});

client/main.html(此处使用blaze)

<head>
<title>resolutions</title>
</head>

<body>
<ul>
{{#each resolutions}}
{{>resolution}}
{{/each}}
</ul>
</body>

<template name="resolution">
<li>{{title}}</li>
</template>

然后我使用meteor mongo shell将一些对象插入到集合中

db.resolutions.insert({title:"test", createdAt:new Date()});

我测试是否将对象插入到集合中

db.resolutions.find()

输出是,

    {
"_id": ObjectId("589c8d1639645e128780c3b4"),
"title": "test",
"createdAt": ISODate("2017-02-09T15:39:02.216Z")
}

但在客户端 View 中,对象标题未按预期显示在列表中。相反,会看到一个空白屏幕。

最佳答案

看起来您已经快完成了,但似乎缺少发布和订阅您的收藏的正确声明。

您可以在官方 Meteor 教程中找到有用的文档:https://www.meteor.com/tutorials/blaze/publish-and-subscribe

关于javascript - 如何在 Meteor JS 客户端主视图中显示 Mongodb 集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42140983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com