[英]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.