【发布时间】:2016-12-02 04:26:10
【问题描述】:
我无法打印从流星集合中获取的内容。我已经在 /ui/api/collections.js 中声明了我的收藏
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import 'meteor/aldeed:collection2';
export const Courses = new Mongo.Collection("courses");
Courses.allow({
'insert': function () {
// if (Meteor.isEducator(Meteor.userId())) {
return true;
}
})
/imports/api/course.html
<template name="course">
<h2> You are enrolled in the following courses:</h2>
<ul>
{{#each course_list}}
{{> getCourseName}}
{{/each}}
</ul>
</template>
<template name="getCourseName">
<li><h2>{{courseName}}</h2></li>
</template>
/imports/api/course.js
Template.course.helpers({
course_list: function() {
var result = Courses.find({});
console.log("result is:");
console.log(result);
return result;
}
})
我已将 Courses 声明为新的 Mongo.Collection 并将其导入 /server/main.js 然后我将 /imports/api/collections.js 导入 course.js 和 course.html。
the console output of printing course_list's result is :
L…n.Cursor {collection: LocalCollection, sorter: null, matcher: M…o.Matcher, _selectorId: undefined, skip: undefined…}
我注意到它说 LocalCollection 这让我觉得它没有找到实际的集合。当我在服务器端 mongo 控制台上执行 db.courses.find() 时,我看到集合中确实存在两个课程,并且它们都有一个 courseName 字段。我认为我不需要发布/订阅,因为我在导入中声明集合,然后将集合导出为全局变量。我一般是流星和javascript的新手,因此非常感谢任何解释。
【问题讨论】:
标签: javascript mongodb meteor handlebars.js