使用Meteor和Iron Router创建用户配置文件页面

 mobiledu2502907083 发布于 2023-02-09 13:10

我正在使用Meteor和Iron Router构建一个Web应用程序,我的目标之一是为所有用户(可以编辑他的信息)和所有用户的配置文件视图构建一个配置文件视图(可以查看)任何人).

登录用户的配置文件视图运行良好,但我在为其他用户创建用户配置文件视图时遇到问题.当我尝试使用url(eg: localhost:3000/users/"id")直接在浏览器中访问某些用户配置文件时,它会呈现用户登录的数据,并且浏览器中的url会更改为localhost : 3000/users/[object%20Object].

此外,当呈现具有该信息的页面时,带有对该引用的引用的标记始终为空.

以下是与此问题相关的代码:

服务器 - publications.js

Meteor.publish('singleUser', function(userId) {
   return Meteor.users.find(userId);
});

router.js

Router.map(function() { 
    this.route('profile', {
        path:'/profile',
        data: function() {return Meteor.user();}
    });

    this.route('user_profile', {
        path: '/users/:_id',
        waitOn: function() {
                return Meteor.subscribe('singleUser', this.params._id);
        },
        data: function() { 
                var findById = Meteor.users.findOne(this.params._id);
                if (typeof findById !== "undefined") {
             Router.go(getProfileUrlById(findById),  {replaceState: true});
                }
        }
    }); 
});

用户档案模板

 

用户资料助手

Template.user_profile.helpers({
     username: function() {return Meteor.user().username},
     email: function() {return Meteor.user().emails[0].address} 
});

物品模板

 

项目助手

Template.item.helpers({
    profileUrl: function() {
        var user = Meteor.users.findOne(this.userId, {reactive:false});
        if(user)
            return getProfileUrlById(user);
    }
 });

getProfileUrlById = function(id) {
    return Meteor.absoluteUrl()+'users/' + id;
}

用户配置文件登录模板


用户配置文件登录了帮助程序

Template.profile.helpers({
    username: function() {return Meteor.user().username},
    email: function() {return Meteor.user().emails[0].address}
 });

我错过了什么吗?

提前致谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有