【问题标题】:Passing Meteor's Iron Router Parameters to Template Callback将 Meteor 的 Iron Router 参数传递给模板回调
【发布时间】:2014-05-30 09:39:43
【问题描述】:

如何将 Iron Router 参数传递给 Template.myTemplate.rendered 回调?以下路由和回调函数为console.log 提供undefined

网址

http://localhost:3000/story/1234

Router.js

Router.map( function() {

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

})

story.js

Template.story.rendered = function () {

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

}

【问题讨论】:

    标签: javascript node.js meteor


    【解决方案1】:

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

    【讨论】:

    • Np。很高兴我能帮助你。 ;)
    • 当我们将代码转换为移动应用程序时,这会起作用吗?
    • 我认为是这样,但我还没有使用 Meteor 创建任何移动应用程序来验证这一点。
    • 太棒了!正在寻找这个。 @nickytonline 当初学者需要这样的东西时,你会如何搜索它?我自己找不到,所以我google了一下,终于找到了这个解决方案。
    • Stackoverflow 是这样的一个很好的资源。对于您的问题,您可能已经查看了 Iron-router Github 项目页面以及有关 API 的文档,github.com/iron-meteor/iron-router。很高兴能帮到你。
    猜你喜欢
    • 1970-01-01
    • 2015-11-08
    • 2015-06-05
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多