[英]Why aren't any of collections being defined after publishing them?
我一直在瀏覽器控制台中收到以下錯誤消息:
Exception in template helper: ReferenceError: "CollectionNames" is not defined
“ CollectionNames”是我在應用程序中擁有的所有集合。 我已經研究過,但找不到合適的解決方案。
我的環境:
我正在運行流星1.2
在task.js文件中,我定義了每個集合。 下面是task.js中的代碼
/ myMeteorApp
-/ imports / api / tasks.js
import { Mongo } from "meteor/mongo";
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})] });
buyList = new Mongo.Collection("BuyList");
WhoAreWe = new Mongo.Collection("whoDb");
merchantReviews = new Mongo.Collection("merchantReviews");
Messages = new Meteor.Collection("messages", {transform: function (doc)
{ doc.buyListObj = buyList.find({sessionIDz: {$in: [doc.buyList]}}); return doc; }});
服務器是我發布集合的地方。 下面是代碼:
/ myMeteorApp
-/服務器/main.js
import buyList from '../imports/api/tasks.js';
import Messages from '../imports/api/tasks.js';
import Images from '../imports/api/tasks.js';
import WhoAreWe from '../imports/api/tasks.js';
import merchantReviews from '../imports/api/tasks.js';
Meteor.startup(() => {
// code to run on server at startup
Meteor.publish('buyList', function(){
return buyList.find();
});
Meteor.publish('Messages', function(){
return Messages.find();
});
Meteor.publish('Images', function(){
return Messages.find();
});
Meteor.publish('WhoAreWe', function(){
return WhoAreWe.find();
});
Meteor.publish('merchantReviews', function(){
return merchantReviews.find();
});
});
客戶是我訂閱收藏的地方。 在下面的代碼中找到:
/ myMeteorApp
-/ client / main.js
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
Meteor.subscribe('Messages');
Meteor.subscribe('WhoAreWe');
Meteor.subscribe('Images');
Meteor.subscribe('buyList');
我要去哪里錯了。 我已經在這里待了很多天了……請幫助!
必須在客戶端和服務器上都定義集合! 只需在客戶端和服務器上導入集合名稱:
import { buyList, Messages, Images, WhoAreWe, merchantReviews } from '../imports/api/tasks.js';
當然,您仍然必須訂閱各種出版物 。
這是一個命名問題,發布集合時,應引用集合名稱(消息),而不是流星變量(消息)。
Meteor.publish('messages', function(){...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.