Я показываю список элементов, и каждый элемент принадлежит пользователю. Я перечисляю имя элемента, описание и пользователя, создавшего его (по имени). Я также хочу иметь ссылку, которая ведет к пользователю, создавшему элемент. Примечание. Я также ссылаюсь на страницу элемента.
Вот что я сделал до сих пор:
пакеты
aldeed:collection2
aldeed:simple-schema
iron:router
aldeed:autoform
useraccounts:iron-routing
accounts-password
accounts-base
useraccounts:core
zimme:active-route
todda00:friendly-slugs
reywood:publish-composite
клиент/элементы/listed_item.html
<template name="listedItem">
<a href="{{pathFor 'itemPage'}}">
{{name}}
</a>
<a href="{{pathFor 'profile'}}">
{{usernameFromId user}}
</a>
</template>
клиент/предметы/items.html
<template name="items">
<div class="items">
{{#each items}}
{{> listedItem}}
{{/each}}
</div>
</template>
клиент/subscriptions.js
Meteor.subscribe('items');
Meteor.subscribe('allUsernames');
Meteor.subscribe('users');
клиент/helpers.js
Template.items.helpers({
items: function() {
return Items.find();
},
});
Template.registerHelper("usernameFromId", function (userId) {
var user = Meteor.users.findOne({_id: this.userId});
return user.profile.name;
});
сервер/publications.js
Meteor.publish("items", function () {
return Items.find();
});
Meteor.publish("users", function () {
return Meteor.users.find({}, {
fields: { profile: 1 }
});
});
Meteor.publish("allUsernames", function () {
return Meteor.users.find({}, {
fields: { 'profile.name': 1, 'services.github.username': 1 }
});
});
библиотека/routes.js
Router.route('/items', function () {
this.render('items');
});
Router.route('/users/:_id', {
template: 'profile',
name: 'profile',
data: function() {
return Meteor.users.findOne({_id: this.params._id});
}
});
Однако это показывает URL-адрес элементов для URL-адреса пользователя, поэтому он ссылается на несуществующего пользователя. то есть items/1234
= users/1234
когда в системе есть только пользователи/1. Как я могу заставить его связать с правильным идентификатором пользователя?