流星1.0-将参数传递到pathFor使用iron:router [英] Meteor 1.0 - Passing a parameter into pathFor using iron:router
问题描述
我已经看到了一些有关如何使用iron:router作为第三个参数传递参数的答案,例如:href="{{pathFor 'article' _id=this._id }}"
I've seen a few answers on how to pass a parameter using iron:router as the third parameter, for example: href="{{pathFor 'article' _id=this._id }}"
我想做的就是传递一个参数作为 second 变量(在上面的示例中,其中'article'
).
What I would like to do is pass a parameter as the second variable (where 'article'
is in the example above).
我有一个posts
集合,其中包含一个title
,一个body
和一个type
.我正在研究的项目中有三种类型的文章,并且每种类型都需要路由到不同的模板,因为格式明显不同.
I have a collection of posts
that contain a title
, a body
, and a type
. There are three types of articles in the project I'm working on, and each type needs to be routed to a different template because the formatting is significantly different.
我想做的就是根据类型路由到特定的url.捕获我的意图但不起作用的示例如下:
What I would like to be able to do is route to a particular url based on the type. An example that captures my intent but doesn't work would be this:
<a href="{{pathFor '{{type}}'}}">link</a>
查询"是类型"之一,其路线如下所示:
One of the "types" is "inquiry", and the route looks like this:
@route "inquiryPost",
path: "inquiry/:_id"
data: ->
Posts.findOne @params._id
waitOn: ->
[
Meteor.subscribe "posts"
]
我尝试使用帮助程序将值传递到pathFor
,但这也不起作用:
I've tried using a helper to pass the value into the pathFor
, but that didn't work either:
path: ->
type = @type
"pathFor '#{type}'"
...在前端:
<a href="{{path}}">link</a>
我可以考虑一些解决方法,但是在我看来,应该有一种更简单的方法来传递参数...
I can think of a few work arounds, but it seems to me like there should be an easier way to pass in parameters...
那么,是否可以将参数传递到pathFor的第二个值中?
So, is it possible to pass in parameters into the second value of a pathFor?
推荐答案
尝试
<template name="example">
<a href="{{pathFor type}}">link</a>
</template>
类型是助手
Template.example.examples({
type:function(){
return type;
}
})
例如,您也可以尝试使用
Also you can try with this for example
<a href="/myRoute/{{myHelper}}/{{this._id}}">link with many parameters</a>
在这里您可以访问路线
/myRoute/type/rewr8671qew
这篇关于流星1.0-将参数传递到pathFor使用iron:router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!