从MongoDB到模板的HTML
我有一个Mongo集合,其中包含以下文档:从MongoDB到模板的HTML,mongodb,templates,meteor,Mongodb,Templates,Meteor,我有一个Mongo集合,其中包含以下文档: { "header": "<h2>Header 2</h2>", "body": "<p>A paragraph.</p>", "subheader": "<h2>What is the ‘fish’?</h2>", "paragraph": "<p>A fish is a fish.</p>",
{
"header": "<h2>Header 2</h2>",
"body": "<p>A paragraph.</p>",
"subheader": "<h2>What is the ‘fish’?</h2>",
"paragraph": "<p>A fish is a fish.</p>",
"paragraph2": "<p>Fish like to swim.</p>"
}
没有错误,但模板中没有任何内容
我们有一个集合,我们已经订阅了它,服务器正在发布它
我知道这不是一个很好的解决方案,因为我们必须在Mongo中硬编码模板和文档之间的链接,但现在就可以了。除非有更干净的方法从Mongo获取html并使用它填充模板
谢谢
编辑:我打字打错了!我的错。因此,新的错误:
未捕获错误:应为模板或空,在Spacebars-runtime.js中找到:[object]
及
未捕获错误:无法在View.js中渲染同一视图两次
我将通过以下方式发布该系列:
Meteor.publish("panels", function() {
return Panels.find({});
});
如果你像你提到的那样想要一张唱片,我会这样做
<template name="panel">
{{#with panels}}
{{{header}}}
{{/each}}
</template>
{{#带面板}
{{{header}}}
{{/每个}}
关于车把的问题-更好的方法是使用安全绳,
检查一下,我不久前也遇到过同样的问题不要这样做。这种方法与Meteor所要做的一切背道而驰。这与任何MVC框架都是背道而驰的(顺便说一句,Meteor不是MVC框架所必需的)。为每个段落文本创建一个模板并将Mongo集合中的数据绑定到该模板非常简单。只要从Meteor网站开始,你就会看到最基本的教程。e、 g
<template name="main">
<h2>{{panels.subheader}}</h2>
</template>
Template.main.helpers({
panels: function() {
return Panels.find({})
}
});
{{panels.subheader}}
Template.main.helpers({
面板:函数(){
返回面板。查找({})
}
});
(顺便说一句,这并不是你问题的完整答案)也许答案可以和那条评论的开头一样:)直率+诚实=好。整理好了。
<template name="panel">
{{#with panels}}
{{{header}}}
{{/each}}
</template>
<template name="main">
<h2>{{panels.subheader}}</h2>
</template>
Template.main.helpers({
panels: function() {
return Panels.find({})
}
});