为什么我的集合返回[object Object]而不是我插入的文本字符串?

时间:2014-02-26 05:17:59

标签: javascript meteor

在我的Meteor应用程序中,我的收藏有问题,只返回[object Object]而不是我插入的文本字符串。

在控制台中,键入MyCollection.insert({sometext: "hello"});我将“hello”插入某个文本中。现在您可以在下面的代码中看到,带有{{output}}的模板infoOutput将返回我插入的内容。现在它可以正常工作,除了它在我将[object Object]放入模板的div中显示{{output}}

我希望能够显示字符串“hello”或我插入的任何文本字符串。我还希望能够更新和写入该文本字符串,因此不会返回一个文本字符串列表,我只想要一个字符串,并且每次以Session方式插入新的文本字符串时都要更改该字符串。 set会改变一个字符串。

我很感激帮助。谢谢

在我的client.js文件中,我有:

MyCollection = new Meteor.Collection('MyCollection');

if(Meteor.isClient) {
Template.infooutput.output = function() { 
return MyCollection.findOne(); }
}

在我的server.js文件中,我有:

MyCollection = new Meteor.Collection('MyCollection');
if (Meteor.isServer) {
}

我有一个模板:

<template name="infoOutput">
<div id="outputText">
{{output}} 
</div>
</template>

然后在我的主页

<body>
{{>infoOutput}}
</body>

1 个答案:

答案 0 :(得分:0)

试试这个

<template name="infoOutput">
<div id="outputText">
{{output.sometext}} 
</div>
</template>