2015-10-07 143 views
1

我有'文章'和詳細視圖的列表視圖。這些航線使用鐵路路由器無法訪問流星中的參數

this.route("articles", {path: "/articles", controller: "ArticlesController"}); 
this.route("article", {path: "/articles/:_id", controller: "ArticleController"}); 

內模板/文章,我有一個鏈接到詳細信息視圖

<a href="{{pathFor 'article' id=this._id }}"><i class="portlet-icon portlet-icon-maximize"></i></a> 

頁面被正確地嵌入ID呈現,如:

<a href="/articles/gb6KgxbnfBeynz4rH"> 
    <i class="portlet-icon portlet-icon-maximize"></i> 
</a> 

在我的控制器關聯的路線,我不能訪問參數,它是空的。

this.ArticleController = RouteController.extend({ 
    template: "Article", 

    onBeforeAction: function() { 
     this.next(); 
    }, 

    action: function(){ 
     if (this.isReady()) { 
     this.render(); 
     } else { 
     this.render("loading"); 
     } 
    }, 

    isReady: function() { 
     var ready = true; 
     var subs = [ Meteor.subscribe('singleArticle')]; 
     _.each(subs, function(sub) { 
     if(!sub.ready()) 
      ready = false; 
     }); 
     return ready; 
    }, 

    data: function() { 
     console.log(Iron.Location.get()); 
     console.log("params: " + this.params); 

     return { 
      article: Articles.findOne({articleId:this.params._id}, {})   
     }; 
    } 
}); 

從JavaScript控制檯我可以看到_id與傳遞的url,但我不能訪問this.params

Javascript Console

+1

怎麼樣' Router.current()。params'? – Sindis

+0

你確定你使用的是最新版本的'iron-router'嗎? –

+0

鐵:[email protected] – ardochhigh

回答

1

的問題是,你正在使用console.log

console.log("params: " + this.params); 

params對象實際上是一個零長度的數組。你可以在這裏閱讀討論一下:https://github.com/iron-meteor/iron-router/issues/1213

所以,你可以在各個PARAMS使用的console.log,它會工作:

console.log("params._id: " + this.params._id); 

或者你可以使用:

console.dir("params: " + this.params);