【发布时间】:2015-12-18 10:03:00
【问题描述】:
我有以下 HTML:
<template name="something">
{{#each biller}}
<div>write_something</div>
{{/each}}
</template>
#each biller 的助手如下:
billers = new Mongo.Collection("billers");
Template.something.helpers({
biller: function(param){
return billers.find({param:param}) ;
}
});
这在部署到 localhost 时可以正常工作。但是,当我使用 meteor deploy 部署到 subdomain.meteor.com 时,#each biller 内的 div 显示为空 - 没有内容。然后我用return ['a','b'](一些数组)替换了助手中的billers.find(),它又可以正常工作了。所以我把问题缩小到billers.find()在部署时没有按预期工作,也许它无法连接到数据库。虽然这不起作用,但在浏览器控制台中我看到以下消息:WebSocket connection to 'wss://ddp--3592-biller2.meteor.com/sockjs/969/mty9hj18/websocket' failed: WebSocket is closed before the connection is established.
cbd6db56612e463370fc8f0b4c909d896b48d176.js:32 WebSocket connection to 'wss://ddp--5246-biller2.meteor.com/sockjs/849/wr1l0s5w/websocket' failed: WebSocket is closed before the connection is established. 我不知道此错误消息是否与我面临的问题有关。有关如何解决此问题的任何想法?
更新:
我在下面的评论中提到的助手中添加了一行:if(billers.find().count()==0) console.log("zero") else console.log("not zero")
在本地主机上运行时,它给出“非零”,而在 subdomain.meteor.com 上运行时,它打印“零”。所以我猜,find() 正在工作,但它获取零个文档。为什么会这样?
【问题讨论】:
-
您的应用程序中是否存在夹具数据?有关更多信息,我要问的是您是否有信息说 if (CollectionName.find().count() === 0 ) { //insert data } ?
-
@thatgibbyguy 谢谢,用这个细节更新了问题。