我有一些相关的集合,其中一个是Decisions
,其中包含此字段
submittedBy: {
type: Schema.user,
autoValue: function() {
if (this.isInsert) {
return this.userId;
} else {
this.unset();
}
}
}
因此,当记录的用户发布Decision
时,此字段包含其userId,但是当我使用{{#each}}
将数据检索到HTML时,字段{{submittedBy}}
只有它的userId ...我想要检索用户的对象或者操纵它,例如渲染文本的用户名和<a href="/users/{{ submittedBy.userId }}">{{ submittedBy.username }}</a>
标签的userId。
扩展Users
有此字段
decisions: {
type: [Schema.Decision],
optional: true
}
我希望每个Decision
用户填写的内容已发布...
我正在使用autoforms
和collection2
这里是完整架构,如果你想看看
Decisions = new Meteor.Collection("decisions");
var Schema = {};
Schema.Decision = new SimpleSchema({
title: {
type: String,
label: "Título",
max: 149
},
description: {
type: String,
label: "Descripción",
max: 149,
optional: true
},
blue: {
type: String,
label: "Opción Azul",
max: 149
},
blueTotal: {
type: Number,
label: "Votos Azules",
min: 0,
defaultValue: 0,
optional: true
},
red: {
type: String,
label: "Opción Roja",
max: 149
},
redTotal: {
type: Number,
label: "Votos Rojos",
min: 0,
defaultValue: 0,
optional: true
},
createdAt: {
type: Date,
label: "Fecha envío",
optional: true,
autoValue: function () {
if (this.isInsert) {
return new Date;
} else {
this.unset();
}
},
denyUpdate: true
},
submittedBy: {
type: Schema.user,
autoValue: function() {
if (this.isInsert) {
return this.userId;
} else {
this.unset();
}
}
},
tags: {
type: [String],
label: "Tags",
minCount: 1
}
});
Schema.User = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id
},
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: Schema.UserProfile,
optional: true
},
decisions: {
type: [Schema.Decision],
optional: true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}$/,
optional: true
},
lastName: {
type: String,
regEx: /^[a-zA-Z]{2,25}$/,
optional: true
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
},
website: {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true
},
bio: {
type: String,
optional: true
},
country: {
type: Schema.UserCountry,
optional: true
}
});
Schema.UserCountry = new SimpleSchema({
name: {
type: String
},
code: {
type: String,
regEx: /^[A-Z]{2}$/
}
});
Decisions.allow({
insert: function() {
return true;
},
update: function() {
return false;
},
remove: function() {
return false;
},
fetch: []
});
Decisions.attachSchema(Schema.Decision);
Meteor.users.attachSchema(Schema.User);