我无法让我的非常简单的 meteor 教程读取我在 Mongodb 中的集合并打印到页面。这是在meteor网站上找到的官方教程。任何帮助将非常感激。如果有人想连接到工作区并进行更改,请告诉我,我可以授予访问权限。
这是我的工作区的链接:https://ide.c9.io/hilldesigns/meteor
Tasks = new Mongo.Collection("tasks");
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: function () {
return Tasks.find({});
}
});
}
这是 HTML 标记:
<head>
<title>Todo List</title>
</head>
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
最佳答案
不确定是否将助手附加到主体,1.2.1(最新版本)不支持它。如果您在浏览器中打开控制台,它应该显示有关无法访问未定义的帮助程序的错误。
所以,为了让它发挥作用......
<head>
<title>Todo List</title>
</head>
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
{{> todos}}
</div>
</body>
<template name="todos">
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</template>
<template name="task">
<li>{{text}}</li>
</template>
与
Tasks = new Mongo.Collection("tasks");
if (Meteor.isClient) {
// This code only runs on the client
Template.todos.helpers({
tasks: function () {
return Tasks.find({});
}
});
}
工作正常
这是我的 meteor 列表
autopublish 1.0.4 (For prototyping only) Publish the entire database to all clients
blaze-html-templates 1.0.1 Compile HTML templates into reactive UI with Meteor Blaze
ecmascript 0.1.6* Compiler plugin that supports ES2015+ in all .js files
es5-shim 4.1.14 Shims and polyfills to improve ECMAScript 5 support
insecure 1.0.4 (For prototyping only) Allow all database writes from the client
jquery 1.11.4 Manipulate the DOM using CSS selectors
meteor-base 1.0.1 Packages that every Meteor app needs
mobile-experience 1.0.1 Packages for a great mobile user experience
mongo 1.1.3 Adaptor for using MongoDB and Minimongo over DDP
session 1.1.1 Session variable
standard-minifiers 1.0.2 Standard minifiers used with Meteor apps by default.
tracker 1.0.9 Dependency tracker to allow reactive callbacks
meteor 是1.2.1
关于javascript - 将 Meteor 与 MongoDB 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746639/