简体   繁体   English

在MeteorJS中渲染用户个人资料页面

[英]Rendering user profile page in MeteorJS

I'm trying to create a page for users so that when they are logged in they can see the content they've uploaded onto the site. 我正在尝试为用户创建一个页面,以便他们登录后可以看到他们上传到网站上的内容。 I can't seem to get the page to render. 我似乎无法显示页面。 I've searched all over, but can't seem to find anything. 我到处搜寻,但似乎找不到任何东西。 Any ideas of where I'm going wrong? 关于我要去哪里的任何想法?

from my publication.js file

Meteor.publish('myTickets', function() {
  var currentUserId = this.userId;
  return Tickets.find({
    createdBy: currentUserId
  })
});

from the router.js

Router.route('/users/:_id', {
  name: 'userPage',
  waitOn: function() {
    return Meteor.subscribe('myTickets');
  },
  data: function() {
    return Tickets.find({
      userId: this.userId
    })
  }
});

userpage.js

Template.userPage.helpers({
  tickets: function() {
    var currentUserId = Meteor.userId();
    return Tickets.find({
      createdBy: currentUserId
    }, {
      sort: {
        createdAt: -1
      }
    });
  }
});

I asked you in a comment what you exactly wanted to do (you have a route with a parameter, but you are never using it), but anyway, I think I got your problem; 我在评论中问您您到底想做什么(您有一条带有参数的路由,但从未使用过),但是无论如何,我认为我遇到了问题;

You are using this.userId to get your current user ID in your router, but your should use Meteor.userId() instead; 您正在使用this.userId在路由器中获取当前用户ID,但应使用Meteor.userId()代替; this.userId can only be used in publish methods. this.userId只能在发布方法中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM