Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Iron Router为Twitter用户生成URL_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript 使用Iron Router为Twitter用户生成URL

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

我有一些用户通过Twitter登录到Meteor应用程序。我想用Iron Router为他们创建一个个人资料页面路由,该路由引用他们的Twitter屏幕名

我不知道应该用什么替换下面的Iron Router代码的
: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};