【发布时间】:2015-02-13 02:10:42
【问题描述】:
我正在尝试 Meteor 中的 reywood:publish-composite 包,但没有基本成功。模板未显示从 MongoDB 集合中提取的字段。
/server/publish.js
Meteor.publishComposite("PDetail", function(pShortname) {
console.log("Browser asked to subscribe to PDetail with: " + pShortname);
return {
find: function() {
return Proj.find( {shortname: pShortname} );
}
}
});
/collections/collections.js
Proj = new Mongo.Collection('proj');
/client/app.js
Router.route('proj', {
path: '/proj/:shortname',
template: 'proj',
waitOn: function() {
return Meteor.subscribe('PDetail', this.params.shortname);
}
});
/client/proj/proj.html
<template name="proj">
<h1>Name: {{pname}}</h1>
</template>
我得到的只是名称:没有 pname 值。
我确认 MongoDB 数据库确实有与短名称查询匹配的集合数据,并且 pname 确实有一个值。在服务器上,我确实看到一条成功的“浏览器要求订阅”console.log 消息,其中传递了短名称(上面显示的 console.log)。
我认为我正确地遵循了发布复合文档,但是在将 Iron Router 添加到组合中时事情变得有点模糊。任何想法将不胜感激!
【问题讨论】:
标签: meteor iron-router