流星路径助手不返回任何东西 [英] Meteor path helper not returning anything

查看:247
本文介绍了流星路径助手不返回任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学习流星,我遵循Sacha Greif的书发现流星。 当前的源代码反映在这里 - > https://github.com/stopachka / meteor-hackernews

to learn meteor, I'm following Sacha Greif's book 'Discovering Meteor'. The current source code is reflected here-> https://github.com/stopachka/meteor-hackernews

现在,我想添加一个讨论链接到post_item,它应该渲染单个post_item。

Right now, I'm trying to add a 'discuss' link to the post_item, which is supposed to render the single post_item.

<template name="postItem">
  <div class="post">
    <div class="post-content">
      <h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
    </div>
    <a href="{{postPagePath title}}" class="discuss btn">Discuss</a>
  </div>
</template>

路由器看起来像这样 - >

The router looks like so ->

Meteor.Router.add
  '/': 'postsList'
  '/posts/:_id':
    to: 'postPage'
    and: (id) ->
      Session.set('currentPostId', id)

目前,浏览器

localhost:3000/posts/foobarid

它呈现相应的帖子

但是当我添加{{postPagePath title}}时,讨论按钮甚至显示href属性。

But when i add the {{postPagePath title}}, the discuss button does not even show the href property. I'm assuming it's because it's not rendering anything.

这里有新的Meteor,任何指导都非常感激。

Super new to Meteor here, any guidance greatly appreciated

推荐答案

这里有几点需要注意:

首先,你使用的路由器软件包Meteor Router不赞成使用Meteor,Iron Router的现在规范的路由包。您可以在流星路由器github页面这里上看到这一点,您可以找到铁路由器规格此处。我怀疑你可能使用了一个较旧版本的Discover Meteor书,因为它现在详细地涵盖铁路由器。如果可能的话,我会试着拿一本铁皮书版本的书,因为这是可以预见的未来的标准。

First, the router package you are using with the tutorial, Meteor Router, has been deprecated in favor of a now-canonical routing package for Meteor, Iron Router. You can see this noted on the Meteor Router github page here, and you can find the Iron Router specifications here. I suspect you may be using an older version of the Discover Meteor book as well, as it now covers Iron Router in detail. If at all possible, I'd try to get my hands on a version of the book covering Iron Router as it will be the standard for the foreseeable future.

其次,你是正确的,href =属性没有显示,因为它不呈现任何东西。具体来说,在Meteor 0.8+中,如果属性的值返回null,undefined或false,那么属性本身将被删除。 在这里阅读更多

Second, you are correct that that href="" property is not showing up because it is not rendering anything. Specifically, in Meteor 0.8+, if the value of an attribute returns null, undefined or false, the attribute itself is removed. Read more here.

最后,虽然我不高速的Meteor路由器的细节,它看起来像快速检查,像你想要传递的PostPagePath的id,而不是帖子的标题,例如{{PostPagePath id}}或类似网址。

Lastly, while I'm not up to speed on the details of Meteor Router it looks on quick inspection like you would want to pass PostPagePath the id and not the title of the post, e.g. {{PostPagePath id}} or similar.

这篇关于流星路径助手不返回任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆