简体   繁体   English

加载模板中的Meteor.js错误

[英]Meteor.js error in loading Templates

Everything was working fine on my app (including the loadingTemplate, which was only being routed when actually required) until I decided to make a simple list on my home template to show every document on a Mongo collection called Rooms, by its title. 一切都在我的应用程序上运行良好(包括loadingTemplate,仅在实际需要时才进行路由),直到我决定在首页模板上列出一个简单列表,以按标题显示名为“房间”的Mongo集合上的每个文档。

WHAT I'VE DONE 我做了什么

HTML: HTML:

<template name="roomsList">
  <div>
    {{#each rooms}}
      {{> roomsListItem}}
    {{/each}}
  </div>
</template>

<template name="roomsListItem">
    <ul>
        <li>{{title}}</li>
    </ul>
</template>

JS: JS:

Template.roomsList.helpers({
    rooms: function() {
        return Rooms.find();
    }
});

As you can see, very basic stuff. 如您所见,非常基本的东西。 The JS is just supposed to return all the documents on the Rooms collection (there are not many) so that the {{#each}} code block can iterate on them and catch all the titles to make the <ul> . JS仅应返回Rooms集合上的所有文档(数量不多),以便{{#each}}代码块可以对其进行迭代并捕获所有标题以生成<ul> I'm adding {{> roomsList}} on the home template. 我要在首页模板上添加{{> roomsList}}

PACKAGES I'M USING 我正在使用的包裹

I've seen this mentioned in other #meteor questions, so I'll go ahead and list here: 我已经在其他#meteor问题中看到了这一点,所以我继续在这里列出:

  1. accounts-password 1.0.4 Password support for accounts 帐户密码1.0.4帐户的密码支持
  2. accounts-ui 1.1.3 Simple templates to add login widgets to an app accounts-ui 1.1.3用于将登录小部件添加到应用程序的简单模板
  3. iron:router 1.0.1 Routing specifically designed for Meteor iron:router 1.0.1专为Meteor设计的路由
  4. meteor-platform 1.2.0 Include a standard set of Meteor packages in your app 流星平台1.2.0在您的应用程序中包括一组标准的Meteor软件包
  5. sacha:spin 2.0.4 Simple spinner package for Meteor sacha:spin 2.0.4流星的简单微调程序包

WHAT'S HAPPENING 发生了什么

Well, first, here's the bash error message: 好吧,首先,这是bash错误消息:

I20141118-05:25:21.855(-2)? Exception from sub k7PEn4QcT9McjF8tw ReferenceError: rooms is not defined
I20141118-05:25:21.856(-2)?     at null._handler (app/server/publications.js:2:9)
I20141118-05:25:21.856(-2)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20141118-05:25:21.856(-2)?     at _.extend._runHandler (packages/ddp/livedata_server.js:943)
I20141118-05:25:21.857(-2)?     at _.extend._startSubscription (packages/ddp/livedata_server.js:769)
I20141118-05:25:21.857(-2)?     at _.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582)
I20141118-05:25:21.860(-2)?     at packages/ddp/livedata_server.js:546

I suspect the first line is causing all the others, but I can't work out what it's telling me. 我怀疑第一行是导致所有其他行的原因,但我无法弄清楚它在告诉我什么。 I am calling the collection in other parts of the app, in the same manner, without a problem. 我以相同的方式在应用程序的其他部分调用了集合,没有问题。 So I have no idea what's causing the problem here! 所以我不知道是什么引起了这里的问题!

Secondly, now my home template won't load. 其次,现在我的主页模板将无法加载。 All that's loading is the loading template, which is declared on the Router.settings. 加载的只是加载模板,该模板在Router.settings上声明。 It loads for every URL, and never redirects to anything. 它为每个URL加载,并且永远不会重定向到任何内容。 I tried being logged in and logged off. 我尝试登录并注销。

Finally, the list doesn't even work, because I've put the {{>roomsList}} on the loading template just to see if was working and it wasn't. 最后,该列表甚至不起作用,因为我将{{> roomsList}}放在了加载模板上只是为了查看是否有效。

How can i fix this? 我怎样才能解决这个问题?

UPDATE: I was requested in the comments to share the code for subscription and publishing, as there may be some typos. 更新:注释中要求我共享订阅和发布的代码,因为可能会有一些错别字。 I don't think there are, because I was accessing the collection in another part of the code without problems, but here they are: 我认为没有,因为我在代码的另一部分访问该集合没有问题,但是在这里是:

Publication (on /server): 发布(在/服务器上):

Meteor.publish("rooms", function() {
    return rooms.find();
});

Subscription (on /lib): 订阅(在/ lib上):

Router.configure({
    layoutTemplate: "layout",
    loadingTemplate: "loading",
    notFoundTemplate: "notFound",
    waitOn: function() { return Meteor.subscribe('rooms'); }
});

In your publishing code you have to use Rooms instead of rooms , That is your collection name. 在发布代码中,您必须使用Rooms而不是rooms ,这是您的集合名称。 Like this 像这样

 Meteor.publish("rooms", function() {
   return Rooms.find();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM