Meteor:发布集合并将其附加到适当的用户
我有一个学生用户列表和课程集合。当我发布学生名单时,我想让它显示他们正在参加的课程。我的代码当前显示每个学生在每个学生下参加的所有课程,而不是与单个学生相关的课程 我如何让它在正确的速记下显示正确的类 路径:Meteor:发布集合并将其附加到适当的用户,meteor,Meteor,我有一个学生用户列表和课程集合。当我发布学生名单时,我想让它显示他们正在参加的课程。我的代码当前显示每个学生在每个学生下参加的所有课程,而不是与单个学生相关的课程 我如何让它在正确的速记下显示正确的类 路径:classes.js Template.classes.helpers({ studentList: ()=> { return Meteor.users.find({_id: { $ne: Meteor.userId() }}); },
classes.js
Template.classes.helpers({
studentList: ()=> {
return Meteor.users.find({_id: { $ne: Meteor.userId() }});
},
classes: ()=> {
return Classes.find({_id: { $ne: Meteor.userId() }});
},
});
Schemas.Classes = new SimpleSchema({
class: {
type: String
},
teacherUserId: {
type: String,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
studentUserId: {
type: String,
optional: true,
autoform: {
type: "hidden"
}
}
});
Template.classes.helpers({
classes: ()=> {
return JobOffers.findOne({candidateUserId: this._id});
},
});
路径:classes.html
{{#each studentList}}
{{profile.firstName}}
{{#each classes}}
{{class}}
{{/each}}
{{/each}}
{{#each studentList}}
{{profile.firstName}}
{{#with classes}}
{{class}}
{{/with}}
{{/each}}
路径:Classes.js
Template.classes.helpers({
studentList: ()=> {
return Meteor.users.find({_id: { $ne: Meteor.userId() }});
},
classes: ()=> {
return Classes.find({_id: { $ne: Meteor.userId() }});
},
});
Schemas.Classes = new SimpleSchema({
class: {
type: String
},
teacherUserId: {
type: String,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
studentUserId: {
type: String,
optional: true,
autoform: {
type: "hidden"
}
}
});
Template.classes.helpers({
classes: ()=> {
return JobOffers.findOne({candidateUserId: this._id});
},
});
上面的代码的意思是:“查找类id不等于当前用户id的所有类。”我认为您需要:“查找当前用户id在学生列表中的所有类。”
假设类有一个students
字段,这是一个用户ID数组,您可以这样做:
returnclasses.find({students:Meteor.userId()});
上述代码的意思是:“查找班级id与当前用户id不相等的所有班级。”我想您需要:“查找学生列表中当前用户id所在的所有班级。”
假设类有一个students
字段,这是一个用户ID数组,您可以这样做:
returnclasses.find({students:Meteor.userId()});
当您定义类时:()=>类。查找({u id:{$ne:Meteor.userId()})
您告诉计算机的是:
Every time I ask you for the box labeled 'classes' I want you to go
through the box we called 'Classes' and fill 'classes' with everything
you find that doesn't have the '_id' property set to whatever you find
when you look inside of the box that 'Meteor.userId()' gives you.
这不是你想向你的员工提出的要求。您想问您的员工:
Every time I ask you for the box labeled 'classes' I want you to go
through the box we called 'Classes' and fill 'classes' with everything
that you find where the '_id' is set to a certain string that I am passing
you.
这可能与定义
类时在你的中的某个地方使用的有关:()=>类。查找({u id:{$ne:Meteor.userId()})
你告诉计算机的是:
Every time I ask you for the box labeled 'classes' I want you to go
through the box we called 'Classes' and fill 'classes' with everything
you find that doesn't have the '_id' property set to whatever you find
when you look inside of the box that 'Meteor.userId()' gives you.
这不是你想向你的员工提出的要求。您想问您的员工:
Every time I ask you for the box labeled 'classes' I want you to go
through the box we called 'Classes' and fill 'classes' with everything
that you find where the '_id' is set to a certain string that I am passing
you.
这可能与这个在你的中的某个地方被使用有关,而不是真正为你编写,多亏了大家的投入,我的问题解决了!蒂姆一针见血。对于遇到类似问题的人,请查看下面的代码。我希望有帮助。再次感谢蒂姆
路径:classes.js
Template.classes.helpers({
studentList: ()=> {
return Meteor.users.find({_id: { $ne: Meteor.userId() }});
},
classes: ()=> {
return Classes.find({_id: { $ne: Meteor.userId() }});
},
});
Schemas.Classes = new SimpleSchema({
class: {
type: String
},
teacherUserId: {
type: String,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
studentUserId: {
type: String,
optional: true,
autoform: {
type: "hidden"
}
}
});
Template.classes.helpers({
classes: ()=> {
return JobOffers.findOne({candidateUserId: this._id});
},
});
路径:classes.html
{{#each studentList}}
{{profile.firstName}}
{{#each classes}}
{{class}}
{{/each}}
{{/each}}
{{#each studentList}}
{{profile.firstName}}
{{#with classes}}
{{class}}
{{/with}}
{{/each}}
感谢大家的投入,我的问题解决了!蒂姆一针见血。对于遇到类似问题的人,请查看下面的代码。我希望有帮助。再次感谢蒂姆
路径:classes.js
Template.classes.helpers({
studentList: ()=> {
return Meteor.users.find({_id: { $ne: Meteor.userId() }});
},
classes: ()=> {
return Classes.find({_id: { $ne: Meteor.userId() }});
},
});
Schemas.Classes = new SimpleSchema({
class: {
type: String
},
teacherUserId: {
type: String,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
studentUserId: {
type: String,
optional: true,
autoform: {
type: "hidden"
}
}
});
Template.classes.helpers({
classes: ()=> {
return JobOffers.findOne({candidateUserId: this._id});
},
});
路径:classes.html
{{#each studentList}}
{{profile.firstName}}
{{#each classes}}
{{class}}
{{/each}}
{{/each}}
{{#each studentList}}
{{profile.firstName}}
{{#with classes}}
{{class}}
{{/with}}
{{/each}}
向我们展示您的课程
和学生
收集方案无问题。我已经更新了代码。向我们展示你的班级
和学生
收集方案没有问题。我已经更新了密码。你好,大卫,谢谢你的建议。上面我没有提到这个列表是由老师生成的。所以Metewor.userId()似乎不起作用,我仍然觉得没有足够的信息来回答这个问题。你能展示一个示例类文档吗?你好,大卫,谢谢你的建议。上面我没有提到这个列表是由老师生成的。所以Metewor.userId()似乎不起作用,我仍然觉得没有足够的信息来回答这个问题。你能展示一个示例类文档吗?谢谢@tim。这正是我想要的。我将在下面添加答案,再次感谢!干得好,伙计!我赶时间,在下班前无法写出代码示例。很高兴你弄明白了!谢谢你,蒂姆。这正是我想要的。我将在下面添加答案,再次感谢!干得好,伙计!我赶时间,在下班前无法写出代码示例。很高兴你弄明白了!