【发布时间】:2014-02-26 13:37:55
【问题描述】:
在我的 Meteor 应用程序中,我的集合仅返回 [object Object] 而不是我插入的文本字符串时遇到问题。
在控制台中,输入MyCollection.insert({sometext: "hello"}); 我将“hello”插入到某个文本中。现在您可以在下面的代码中看到,带有{{output}} 的模板 infoOutput 返回我插入的内容。现在它可以工作了,只是它在我将 {{output}} 放入模板中的 div 中显示 [object Object]。
我希望能够显示字符串“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>
【问题讨论】:
-
你不是想得到
{{output.sometext}}吗? -
啊,你是对的。完全忘记了。
-
我该如何替换它?我应该使用更新吗?或使用 Session.set
-
我不了解 Meteor 以及它如何绑定数据 - 第一步当然是给用户一个输入
<input type="text" value="{{output.sometext}}"/>- 。打开另一个问题可能会更好 - 或者在您询问更新的部分非常大胆。 -
@Brandon 你有解决方案吗?
标签: javascript meteor