Javascript 使用Iron Router为Twitter用户生成URL
我有一些用户通过Twitter登录到Meteor应用程序。我想用Iron Router为他们创建一个个人资料页面路由,该路由引用他们的Twitter屏幕名 我不知道应该用什么替换下面的Iron Router代码的Javascript 使用Iron Router为Twitter用户生成URL,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,我有一些用户通过Twitter登录到Meteor应用程序。我想用Iron Router为他们创建一个个人资料页面路由,该路由引用他们的Twitter屏幕名 我不知道应该用什么替换下面的Iron Router代码的:slug部分(我的用户文档中没有属性slug) 首先,必须将slug作为键值对提供,即模板辅助对象中的对象: userScreenName = function() { return Meteor.user().services.twitter.screenName; } Tem
:slug
部分(我的用户
文档中没有属性slug
)
首先,必须将slug作为键值对提供,即模板辅助对象中的对象:
userScreenName = function() {
return Meteor.user().services.twitter.screenName;
}
Template.profileLink.helpers({
slugObject: function () {
return {'slug': userScreenName()};
},
screenName: function () {
return userScreenName();
}
});
现在,您可以使用
a) 带有和块
<template name="profileLink">
<a href="{{#with slugObject}}{{pathFor 'userProfile'}}{{/with}}">{{screenName}}</a>
</template>
b) 直接用作论据
<template name="profileLink">
<a href="{{pathFor 'userProfile' slugObject}}">{{screenName}}</a>
</template>
首先,必须将slug作为键值对提供,即模板辅助对象中的对象:
userScreenName = function() {
return Meteor.user().services.twitter.screenName;
}
Template.profileLink.helpers({
slugObject: function () {
return {'slug': userScreenName()};
},
screenName: function () {
return userScreenName();
}
});
现在,您可以使用
a) 带有和块
<template name="profileLink">
<a href="{{#with slugObject}}{{pathFor 'userProfile'}}{{/with}}">{{screenName}}</a>
</template>
b) 直接用作论据
<template name="profileLink">
<a href="{{pathFor 'userProfile' slugObject}}">{{screenName}}</a>
</template>
首先,必须将slug作为键值对提供,即模板辅助对象中的对象:
userScreenName = function() {
return Meteor.user().services.twitter.screenName;
}
Template.profileLink.helpers({
slugObject: function () {
return {'slug': userScreenName()};
},
screenName: function () {
return userScreenName();
}
});
现在,您可以使用
a) 带有和块
<template name="profileLink">
<a href="{{#with slugObject}}{{pathFor 'userProfile'}}{{/with}}">{{screenName}}</a>
</template>
b) 直接用作论据
<template name="profileLink">
<a href="{{pathFor 'userProfile' slugObject}}">{{screenName}}</a>
</template>
首先,必须将slug作为键值对提供,即模板辅助对象中的对象:
userScreenName = function() {
return Meteor.user().services.twitter.screenName;
}
Template.profileLink.helpers({
slugObject: function () {
return {'slug': userScreenName()};
},
screenName: function () {
return userScreenName();
}
});
现在,您可以使用
a) 带有和块
<template name="profileLink">
<a href="{{#with slugObject}}{{pathFor 'userProfile'}}{{/with}}">{{screenName}}</a>
</template>
b) 直接用作论据
<template name="profileLink">
<a href="{{pathFor 'userProfile' slugObject}}">{{screenName}}</a>
</template>
这并不是说用户文档上应该有slug
属性。这意味着查找其services.twitter.screenName
属性与URL中提供的slug
参数等效的用户文档。“Slug”只是一个术语,意思是URL友好的关键字,即一些只包含字母、数字、连字符和下划线的字符串。@Cuberto是的,对不起,我应该更清楚--Slug
是我自己选择的词。可能是香蕉或任何随机的东西。将浏览器指向localhost:3000/profile/cavill
是可行的,但我希望能够在我的模板中使用{pathFor'userProfile'}}
(我目前无法)。啊,也许你可以做{{{with slug}{{pathFor'userProfile'}{/with}
然后添加一个类似于Template.someTemplate.slug=function()的助手{return{slug:this.user.services.twitter.screenName};};
这并不是说在您的用户文档上应该有slug
属性。这是说查找其services.twitter.screenName
属性与URL中提供的slug
参数等效的用户文档。“slug”只是一个术语,意思是URL友好的关键字,即一些只包含字母、数字、连字符和下划线的字符串。@Cuberto是的,对不起,我应该更清楚--slug
是我自己选择的词。也可以是banana
或任何随机的词。将浏览器指向localhost:3000/profile/cavill
有效,b但是我希望能够在我的模板中使用{{{pathFor'userProfile'}}
(我目前不能)。啊,也许你可以做{{{with slug}{{{pathFor'userProfile}{{/with}
,然后添加一个像Template.someTemplate.slug=function(){return{slug:this.user.services.twitter.screenName};};
这并不是说你的用户文档上应该有slug
属性。这是说查找其服务的用户文档。twitter.screenName
属性相当于URL中提供的slug
参数。“slug”只是一个术语,意思是URL友好的关键字,即一些只包含字母、数字、连字符和下划线的字符串。@Cuberto是的,对不起,我应该更清楚--slug
是我自己选择的词。也可以是banana
或任何随机的词。将浏览器指向localhost:3000/profile/cavill
有效,b但是我希望能够在我的模板中使用{{{pathFor'userProfile'}}
(我目前不能)。啊,也许你可以做{{{with slug}{{{pathFor'userProfile}{{/with}
,然后添加一个像Template.someTemplate.slug=function(){return{slug:this.user.services.twitter.screenName};};
这并不是说你的用户文档上应该有slug
属性。这是说查找其服务的用户文档。twitter.screenName
属性相当于URL中提供的slug
参数。“slug”只是一个术语,意思是URL友好的关键字,即一些只包含字母、数字、连字符和下划线的字符串。@Cuberto是的,对不起,我应该更清楚--slug
是我自己选择的词。也可以是banana
或任何随机的词。将浏览器指向localhost:3000/profile/cavill
有效,b但是我希望能够在我的模板中使用{{{pathFor'userProfile'}}}
(我目前不能)。啊,也许你可以做{{{{with slug}}{{{pathFor“userProfile”}{{/with}
,然后添加一个像Template.someTemplate.slug=function(){return{slug:this.user.services.twitter.screenName};