将Meteor Iron Router参数传递给模板回调函数

10

如何将Iron Router参数传递给Template.myTemplate.rendered回调函数?以下路由和回调函数对于console.log都会返回undefined

URL

http://localhost:3000/story/1234

Router.js

Router.map( function() {

    this.route('story', {
        path: '/story/:_id',
        template: 'story'
    })

})

故事.js

Template.story.rendered = function () {

    console.log('params: ', this.params)    // undefined
    console.log('_id: ', this._id)    // undefined

}
1个回答

25
你尝试过 Router.current().params 吗?

没问题。很高兴能帮忙。;) - nickytonline
当我们将代码转换为移动应用程序时,这个会起作用吗? - user1787687
我认为是这样,但我还没有使用Meteor创建过任何移动应用程序来验证这一点。 - nickytonline
太棒了!一直在找这个。@nickytonline,当初学者需要这样的东西时,你会如何搜索呢?我自己找不到,所以我谷歌搜索最终找到了这个解决方案。 - flowen
Stackoverflow是一个很好的资源,可以解决这类问题。就你的问题而言,你可能已经在iron-router的Github项目页面上查找了关于API的文档,链接为https://github.com/iron-meteor/iron-router。很高兴能帮到你。 - nickytonline

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接