![](/img/trans.png)
[英]How to display particular client name in next template using `meteor Js`?
[英]Display single item in Mongo Db using meteor js using template based subscription
我不知道问题是什么,我有这个代码片段可以显示单个项目,但不能正常工作,我该怎么办?
发布文件:
Meteor.publish('SingleSchool', function (myslug) {
check(myslug, String);
if (!this.userId) {
throw new Meteor.Error('Not authorized');
return false;
} else {
return SchoolDb.find({slug: myslug});
}
})
模板基本订阅:
Template.view.onCreated(function () {
var instance = this;
instance.autorun(function () {
var slug = FlowRouter.getParam('myslug');
return Meteor.subscribe('SingleSchool', slug);
});
});
路线:
FlowRouter.route('/school/:myslug', {
name: 'view',
action: function (params) {
BlazeLayout.render('sidebarschool', {sidebars: 'view'});
}
})
模板文件:
<template name="view">
{{#if currentUser}}
{{#if Template.subscriptionsReady }}
{{#if SingleSchool}}
{{#with SingleSchool}}
<p>{{varibablecalled}}</p>
{{/with}}
{{else}}
<p>Loading...</p>
{{/if}}
{{/if}}
</template>
您是否在模板中初始化了要读取的SingleSchool
集合?
另外,不要忘记这是collection ,因此您应该执行SingleSchool.findOne({slug:...})
以获得所需的项目。
顺便说一句,您的模板文件看起来像是一团糟:两个<template...>
标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.