2015-01-21 13 views
0

我是流星的新手,並且與流星有一些小問題。 我創建了一個鏈接,它是 http://localhost:3000/game?id=7lJ8F 如何獲取查詢字符串中的id值並將其返回給幫助程序。 我找了答案,但沒有找到答案。MeteorJs獲取模板幫助器的查詢字符串數據使用

Router.route('/game/:_id', function(){ 
    Session.set("gameid",this.params.query.id); 

    }); 
    Template.gamebefore.helpers({ 
    ids: function() { 
     return Session.get("gameid"); 
    } 
    }); 

我知道這是錯的,但我非常渴望找到答案,所以任何幫助。謝謝!

+0

嘗試用'Session.set( 「遊戲ID」,this.params._id);' – Ethaan 2015-01-21 07:58:39

回答

0

如何處理,並得到一個URL的參數在guide of iron router

描述,您可能會錯過_:

this.params.query.id 

應該

this.params.query._id 

,反之亦然,因爲在你的網址是

/game?id=7lJ8F 

在您的路線其

Router.route('/game/:_id', function(){ 
-1

你不需要在路由的ID:

Router.route('/game', function(){ 
    Session.set("gameid",this.params.query.id); 

    }); 
    Template.gamebefore.helpers({ 
    ids: function() { 
     return Session.get("gameid"); 
    } 
    }); 

作爲一個說明,而不是使用http://..../game?id=somegameid,你可能想通過使用更REST方法使用http://.../game/somegameid,在這種情況下,你需要這條路線:

Router.route('/game/:_id', function(){ 
    Session.set("gameid",this.params._id); 

    }); 
    Template.gamebefore.helpers({ 
    ids: function() { 
     return Session.get("gameid"); 
    } 
    });