【问题标题】:Meteor Publish Composite is not working with Iron RouterMeteor Publish Composite 不适用于 Iron Router
【发布时间】: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


    【解决方案1】:

    你的路由函数需要返回一个数据上下文;

    Router.route('proj', {
      path: '/proj/:shortname',
      template: 'proj',
      waitOn: function() {
        return Meteor.subscribe('PDetail', this.params.shortname);
      }
      data: Proj.findOne({shortname: this.params.shortname});
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      • 2013-11-21
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多