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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
Meteor 如何路由到用户配置文件页面?_Meteor_Meteor Blaze_Meteor Accounts_Meteor Helper - Fatal编程技术网

Meteor 如何路由到用户配置文件页面?

Meteor 如何路由到用户配置文件页面?,meteor,meteor-blaze,meteor-accounts,meteor-helper,Meteor,Meteor Blaze,Meteor Accounts,Meteor Helper,我显示一个项目列表,每个项目都属于一个用户。我列出了项目的名称、描述以及创建该项目的用户的名称。我还希望有一个指向创建项目的用户的链接。注意:我还链接到一个项目的页面 以下是我迄今为止所做的工作: 包裹 client/items/listed_item.html client/helpers.js server/publications.js lib/routes.js 不过,这会显示用户URL的项目URL,因此它会链接到不存在的用户。i、 e.items/1234=系统中只有用户/1时的用户/

我显示一个项目列表,每个项目都属于一个用户。我列出了项目的名称、描述以及创建该项目的用户的名称。我还希望有一个指向创建项目的用户的链接。注意:我还链接到一个项目的页面

以下是我迄今为止所做的工作:

包裹

client/items/listed_item.html

client/helpers.js

server/publications.js

lib/routes.js


不过,这会显示用户URL的项目URL,因此它会链接到不存在的用户。i、 e.items/1234=系统中只有用户/1时的用户/1234。如何让它链接到正确的用户ID?

使用带有构造URL的链接

<template name="listedItem">
  <a href="{{pathFor 'itemPage'}}">
    {{name}}
  </a>
  <a href="http://yourdomain.com/users/{{user}}">
    {{usernameFromId user}}
  </a>
</template>

使用带有构造URL的链接

<template name="listedItem">
  <a href="{{pathFor 'itemPage'}}">
    {{name}}
  </a>
  <a href="http://yourdomain.com/users/{{user}}">
    {{usernameFromId user}}
  </a>
</template>
在本部分:

Router.route('/users/:_id', {
  template: 'profile',
  name: 'profile',
  data: function() {
  return Meteor.users.findOne({_id: this.params._id});
 }
});
您已经引用了该路由并创建了一个路由,指向名为profile的模板,但我看不到任何具有该名称的模板。有没有可能你忘了把它包括在这里?或者你真的没有那个模板

只是确定一下。

在这部分:

Router.route('/users/:_id', {
  template: 'profile',
  name: 'profile',
  data: function() {
  return Meteor.users.findOne({_id: this.params._id});
 }
});
您已经引用了该路由并创建了一个路由,指向名为profile的模板,但我看不到任何具有该名称的模板。有没有可能你忘了把它包括在这里?或者你真的没有那个模板

只是确定一下。

试试这个:

Router.route('/users/:_id', {
 template: 'profile',
 name: 'profile'
}
在helper中,您可以通过以下方式检索该记录id:

Router.current().params._id
试试这个:

Router.route('/users/:_id', {
 template: 'profile',
 name: 'profile'
}
在helper中,您可以通过以下方式检索该记录id:

Router.current().params._id
我通常用这种方式: 在模板中:

<div class="css-light-border">
    <a href="/document/{{_id}}">{{title}}</a>
</div><!-- / class light-border -->
这里docid基本上是我想要显示的文档的_id。以下是如何从数据库中提取的示例:

somehelper:function(){
        var currentId = Session.get('docid');
        var product = Products.findOne({_id:currentId});
        return product; 
我认为这是一种简单的方法,因为它使用会话。

我通常使用这种方法: 在模板中:

<div class="css-light-border">
    <a href="/document/{{_id}}">{{title}}</a>
</div><!-- / class light-border -->
这里docid基本上是我想要显示的文档的_id。以下是如何从数据库中提取的示例:

somehelper:function(){
        var currentId = Session.get('docid');
        var product = Products.findOne({_id:currentId});
        return product; 

我认为这是一种简单的方法,因为它使用会话。

只是一个问题:在client/helpers.js中,您有一个参数userId,但在函数中您使用this.userId。你可能打算用userId参数找到用户吗?@JosHarink是的,没错。我想让那里的助手为任何模板查找用户字段。只是一个问题:在client/helpers.js中,您有一个参数userId,但在函数中使用this.userId。你可能打算用userId参数找到用户吗?@JosHarink是的,没错。我希望那里的助手为任何模板查找用户字段。如果我使用这种方法,我将如何处理使用localhost?这看起来像是硬编码的。抱歉,我写了完整的URL以明确它是什么,但是您当然可以使用相对路径:错误消息?问题是什么?如果你在浏览器中导航到正确的url,你会看到你的模板吗?我知道你的问题是获取正确的用户ID!所以问题是项目与用户的关系如何?您在listedItem中有用户ID吗?我认为您的“user”变量是正确的userID,但显然这就是问题所在。如果userID在item对象中,则可以使用this.userID或它所在的任何对象路径访问它。如果您需要更多详细信息,请发布item对象的格式如果我使用此方法,我将如何使用localhost?这看起来像是硬编码的。抱歉,我写了完整的URL以明确它是什么,但是您当然可以使用相对路径:错误消息?问题是什么?如果你在浏览器中导航到正确的url,你会看到你的模板吗?我知道你的问题是获取正确的用户ID!所以问题是项目与用户的关系如何?您在listedItem中有用户ID吗?我认为您的“user”变量是正确的userID,但显然这就是问题所在。如果userID在item对象中,则可以使用this.userID或它所在的任何对象路径访问它。如果需要更多详细信息,请发布项目对象的格式
Router.route('/document/:_id', function(){
    Session.set('docid', this.params._id);
    this.render('navbar', {to: "header"});
   this.render('docItem', {to: "main"});
  }); 
somehelper:function(){
        var currentId = Session.get('docid');
        var product = Products.findOne({_id:currentId});
        return product;