流星内容不显示

Meteor content not displaying

我在使用 Flow Router 或我的模板级订阅时遇到问题,但数据未在页面上呈现。

以防万一问题不是我粘贴在这里的内容,我在整个 github 存储库中包含了一个 link:https://github.com/adjohnston/checkr-meteor

lib/routes.js

listRoutes.route('/:slug', {
  name: 'list',

  subscriptions: function (params) {
    this.register('singleList', Meteor.subscribe('singleList', params.slug));
  },

  action: function () {
    FlowLayout.render('mainLayout', {
      main: 'list'
    });
  }
});

server/publication/lists.js

Meteor.publish('singleList', function (slug) {
  return Lists.find({slug: slug});
});

client/lists/list.js

Template.list.helpers({
  singleList: function () {
    return Lists.find();
  }
});

client/lists/list.html

<template name="list">

  {{#if isSubReady}}
    {{#with singleList}}

      <h2>Name: {{name}}</h2>

    {{/with}}
  {{/if}}

</template>

解决方案

将 returns Lists.find() 更改为 Lists.findOne(),因为发布 'singleList' 仅返回一个结果。

client/lists/list.js

Template.list.helpers({
  singleList: function () {
    return Lists.findOne();
  }
});

尝试将您的 singleList 助手更改为 findOne:

Template.list.helpers({
  singleList: function () {
    var slug = FlowRouter.getParam("slug");
    return Lists.findOne({slug: slug});
  }
});

现在您正在尝试显示光标的 name 属性,这就是 find() returns。您的车把也不需要 {{#with singleList}}