2014-10-10 144 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, 
     }; 
    }