Javascript 如何用流星火焰渲染路线相关的副标题?
我将要讨论的所有内容的最终结果是,副标题没有像我希望的那样在屏幕上呈现 目前有一个mongo collection子标题,带有Javascript 如何用流星火焰渲染路线相关的副标题?,javascript,mongodb,meteor,routes,meteor-blaze,Javascript,Mongodb,Meteor,Routes,Meteor Blaze,我将要讨论的所有内容的最终结果是,副标题没有像我希望的那样在屏幕上呈现 目前有一个mongo collection子标题,带有类别字段和文本字段 Subheader = new Mongo.Collection('subheader'); Meteor.methods({ subheaderInsert: function(subheaderIdAttributes) { check(String); check(subheaderIdAttributes, { texth
类别
字段和文本
字段
Subheader = new Mongo.Collection('subheader');
Meteor.methods({
subheaderInsert: function(subheaderIdAttributes) {
check(String);
check(subheaderIdAttributes, {
texth: String,
category: String
});
var subheaderId = _.extend(postAttributes, {
submitted: new Date()
});
var subheaderId = SubheaderId.insert(subheader);
return {
_id: subheaderId
};
}
});
有一个订阅子标题和其他页面数据的路由
Router.route('/', {
name: 'home',
controller: MissionstatementpostController,
waitOn:function () {
return Meteor.subscribe('subheader', 'home');
}
});
发布功能似乎工作正常
Meteor.publish('subheader', function(cat) {
return Subheader.find({category: cat});
});
mongodb集合中的正确文档正在到达客户端。这一点可以从下面的例子中看出
Subheader.findOne(); output Object {_id: "NPo5cwqgjYY6i9rtx", texth: "ex text", category: "home"}
问题从这里开始
在这种情况下,控制器加载的模板MissionstatementpostController
是postlist
<template name="postsList">
<div class="posts page">
{{> subheader}}
<div class="wrapper">
{{#each posts}}
{{> postItem}}
{{/each}}
</div>
{{#if nextPath}}
<a class="load-more" href="{{nextPath}}">Load more</a>
{{else}}
{{#unless ready}}
{{> spinner}}
{{/unless}}
{{/if}}
</div>
</template>
{{>副标题}
{{{#每个帖子}
{{>positem}
{{/每个}}
{{{#如果下一个路径}
{{else}
{{{#除非准备好}
{{>微调器}
{{/除非}
{{/if}
这是副标题模板
<template name="subheader">
<div class="container">
<p>{{{texth}}}</p>
</div>
</template>
{{{texth}}}
那我把什么搞砸了?
谢谢您必须为您的副标题模板创建模板帮助器。要仅返回
texth
字段,助手如下所示
Template.subheader.helpers({
texth: function() {
var sh = Subheader.findOne();
return sh && sh.texth;
}
});
您可以返回整个文档,并在模板中使用带有帮助程序的#
Template.subheader.helpers({
subh: function() {
return Subheader.findOne();
}
});
<template name="subheader">
{{#with subh}}
<div class="container">
<p>{{{texth}}}</p>
</div>
{{/with}}
</template>
Template.subheader.helpers({
副标题:职能(){
返回子标题findOne();
}
});
{{{带subh}}
{{{texth}}}
{{/与}}
您可以在上找到有关模板帮助程序的详细信息