javascript - 将 Meteor 与 MongoDB 结合使用

标签 javascript mongodb meteor cloud9-ide

我无法让我的非常简单的 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/

相关文章:

javascript - 两个相同的按键事件;只有一部作品

javascript - Google登录成功后加载页面

javascript - 我如何摆脱 slideToggle() 上的跳转?

javascript - 所有回调同时执行,但为什么呢?

javascript - 是否可以在文本区域中索引输入的文本?

json - 执行正确的 MongoDB 查询(类型错误 : Converting circular structure to JSON)

MongoDB - 十进制类型的值怎么样?

php - 在 php 和 javascript 中重新获取请求

node.js - 如果文档的 _id 已经存在,如何将数组元素推送到数组;如果 _id 不存在,如何创建新文档?

meteor - PM2 + meteor 环境设置