javascript - 使用 Flow Router 和 Meteor.js 处理 "no data"场景

标签 javascript meteor router

我想知道如何使用 Meteor 的流路由器处理“无数据”情况。假设我想要一条路线 /article/:slug 我想在上面呈现一篇文章(由 slug 字段获取)以及相关评论(单独的集合) .所以我将定义这样的路线:

FlowRouter.route('/article/:slug', {
  subscriptions: function(params) {
    this.register('article', Meteor.subscribe('articleSlug', params.slug));
    this.register('comments', Meteor.subscribe('commentsByArticleSlug', params.slug));
  },
  action: function() {
    FlowLayout.render('appLayout', { main: "articleDetail" });
  }
});

在模板中,当订阅准备就绪时,我将显示文章详细信息和评论,直到那时我将只显示“正在加载...”文本。

但是,如果 URL 中的 :slug 参数与数据库中的任何文章都不匹配怎么办?我不想继续显示“正在加载...”文本,我想显示某种“找不到文章”的消息。如何做到这一点?

感谢您的任何建议。

更新:我还想指出与此问题相关的 github 讨论:https://github.com/meteorhacks/flow-router/issues/70

最佳答案

这可以通过您的模板完成。

Template.articleDetail.helpers ({
   articleFound: articles.find().count() > 0
});

在您的 View 中,渲染正确的内容取决于articleFound的结果。

关于javascript - 使用 Flow Router 和 Meteor.js 处理 "no data"场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29494359/

相关文章:

javascript - 当按钮具有特定类时弹出窗口

javascript - 在 asp.net 中使用 updatePanel 后,DropDownList 丢失其属性

javascript - Meteor:将 RegExp 对象保存到 session

json - Meteor.http.call(调用URL API)

flutter - 运行滑动启动后模棱两可的导入

reactjs - Prop `aria-current` 不匹配。服务器 : "null" Client: "page"

javascript - 如何按顺序在三个或更多 div 之间切换/切换类?

javascript - window.location.replace 登录表单问题(html、javascript)

javascript - 如何使用当前目录中的文件

macos - SSH -L 连接成功,但本地主机端口转发不起作用 "channel 3: open failed: connect failed: Connection refused"