私は Meteor と Iron Router を使用して Web アプリを構築しています。私の目標の 1 つは、ログインしているユーザーのプロファイル ビュー (ユーザーが自分の情報を編集できる場所) と、すべてのユーザーのプロファイル ビュー (表示できるもの) を作成することです。任意の人によって)。
ログインしているユーザーのプロファイル ビューは正常に機能しますが、他のユーザーのユーザー プロファイル ビューの作成に問題があります。ブラウザーで 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 name="user_profile">
<h4>Username</h4>
<p>{{username}}</p>
<h4>Email:</h4>
<p>{{email}}</p>
</template>
ユーザー プロファイル ヘルパー
Template.user_profile.helpers({
username: function() {return Meteor.user().username},
email: function() {return Meteor.user().emails[0].address}
});
アイテム テンプレート
<template name="item">
</span> <a href="{{profileUrl}}">{{author}}</a>
</template>
アイテム ヘルパー
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 name="profile">
<h4>Username</h4>
<p>{{username}}</p>
<h4>Email:</h4>
<p>{{email}}</p>
</template>
ユーザー プロファイル ログイン ヘルパー
Template.profile.helpers({
username: function() {return Meteor.user().username},
email: function() {return Meteor.user().emails[0].address}
});
何か不足していますか?
前もって感謝します!