javascript - meteor 内容不显示

标签 javascript meteor meteor-blaze

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

为了防止问题不是我在这里粘贴的问题,我添加了整个 github 存储库的链接: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'
    });
  }
});

服务器/出版物/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>

解决方案

由于发布“singleList”仅返回单个结果,因此更改将 Lists.find() 返回为 Lists.findOne()。

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() 返回的内容。您的 Handlebars 中也不需要 {{#with singleList}}

关于javascript - meteor 内容不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30765390/

相关文章:

javascript - Meteor 创建一个可滚动的 div

javascript - 如何在不刷新的情况下在 Rails 4 中提交表单和更新页面元素

javascript - 如何防止 react 表排序和搜索重置

javascript - meteor 法无尽运行

ios - 如何在 IOS 设备上运行我的 Ionic 应用程序(带有 Meteor 后端)?

javascript - 如何从给定上下文数据对象的 meteor 模板生成 HTML 输出(版本 0.8+)

javascript - 在我单击 UI 之前,signInWithPopup Promise 不会执行 .catch。 Angular 和 Firebase

javascript - 使用单个按键从 Vim 中的 HTML 文件跳转到 css 文件中的 CSS 选择器

meteor - Apollo/GraphIQL 显示 "Apollo Server supports only POST requests"?

meteor - 4 级订阅嵌套在 meteor 中