2014-10-10 142 views
0

由於某些原因,當我在路徑中有變量時,pathFor函數不工作。我有一個不同的控制器和路由工作,但不是這個。我不知道爲什麼,並試圖更好地瞭解pathFor函數的工作原理。MeteorJS鐵路由器路徑問題

我的路線

this.route('topPublicLinks', { 
     path: '/:permalinkUser/:permalink/top/:linksLimit?', 
     layoutTemplate: 'layoutPublic', 
     controller: TopicPagePublicBestLinksController 
}); 

控制器

TopicPagePublicBestLinksController = TopicPagePublicController.extend({ 
    sort: {votes: -1, submitted: -1, _id: -1}, 
    nextPath: function() { 
     return Router.routes.topPublicLinks.path({linksLimit: this.limit() + this.increment}) 
    } 
}); 

和pathfor

<a href="{{pathFor 'topPublicLinks'}}" type="button" class="btn btn-white {{activeButtonNav 'top'}}">Top Links</a> 

回答

1

除非pathFor幫手,指定什麼路徑瓦爾應該是數據環境中存在,你必須將它們作爲參數傳遞給幫助器。例如,你不得不說,像

{{pathFor 'topPublicLinks' permalinkUser=someUser permalink=somePermalink linksLimit=someLimit}} 

你可以在值或者通過直接

{{pathFor 'topPublicLinks' permalinkUser='userA' permalink='permalink' linksLimit=10}} 
0

在我的控制器中的數據回報,我不返回任何東西permalinkUser和永久爲空

path: '/:permalinkUser/:permalink/top/:linksLimit?', 

一旦我添加的數據功能和返回permalinkUser和永久鏈接它的工作

data: function() { 
     return { 
      permalinkUser: Topics.findOne({$and:[{permalinkUser: this.params.permalinkUser},{permalink: this.params.permalink}]}).permalinkUser, 
      permalink: Topics.findOne({$and:[{permalinkUser: this.params.permalinkUser},{permalink: this.params.permalink}]}).permalink, 
     }; 
    }