这段代码的主要目的是,当我们在数据库中有数据时,它应该在浏览器上获取和显示。但我无法找到它。
问题是将数据传输到服务器。
运行流星并从浏览器的控制台输入一些值后,我无法在浏览器上看到它们。但是我可以通过使用命令" Tdos.find在控制台中找到它们。 ().fetch()",它显示我输入的数组,但如果我想在mongodb控制台中找到,我们无法找到它。有人可以弄清楚我的问题以及我哪里出错了吗?
<head>
<title>simpletodos</title>
</head>
<body>
{{> todoList}}
</body>
<template name="todoList">
<h3>Todos</h3>
<ul>
{{#each tdos}}
{{> todo}}
{{/each}}
</ul>
<button class="add-todo">Add todo</button>
</template>
<template name="todo">
<li>
{{label}}
</li>
</template>
客户端/ Main.js
if(Meteor.isClient) {
Template.todoList.helpers({
todos: function() {
return Tdos.find();
}
});
if(Meteor.isServer) {
}
}
服务器/ main.js
import { Meteor } from 'meteor/meteor';
Tdos = new Mongo.Collection("tdos");
Meteor.startup(() => {
// code to run on server at startup
});
答案 0 :(得分:0)
在您的服务器中,您可以像这样定义集合:
Tdos = new Mongo.Collection("tdos");
这意味着Mongo中的集合是todos,您可以使用
列出内容db.todos.find()
您可以使用以下方法在mongo中插入记录:
db.todos.insert({label: "My first to do"})
在Meteor中,当您想要获取或插入/更新时,可以使用Tdos,例如
Tdos.insert(...};
您的帮助程序允许数据作为代码中的数组提供。我认为你需要将其改为
todos: function() {
return Tdos.find().fetch();
}