【发布时间】:2016-05-07 20:49:21
【问题描述】:
我是 Meteor 和编程的新手,如果这没有意义或者您需要更多信息,请告诉我。
我正在加载另一个用户的个人资料页面。所以我有 2 个用户 ID; this.userId 和其他用户 ID。我想在执行操作时使用 autoValue 来保存两个 userId。即使我可以在 html 页面上显示它,我也不知道如何设置其他用户 ID。
路径:schema.js
Schemas.class = new SimpleSchema({
Title: {
type: String,
optional: true
},
teacherProfile: {
type: String,
optional: true,
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
studentProfileId: {
type: String,
optional: true,
type: String,
autoform: {
defaultValue: "studentProfileId",
type: "hidden"
}
}
});
路径:profile.js
Template.teacherProfile.helpers({
studentProfile: ()=> {
var id = FlowRouter.getParam('id');
return Meteor.users.findOne({_id: id});
}
});
【问题讨论】:
-
我认为您不能使用自动值来设置它,因为 SimpleSchema 没有查看 DOM 或模板数据上下文 afaik。您应该在事件处理程序中设置
otherUserProfileId,或者更好,只需将隐藏字段值设置为它。 -
谢谢米歇尔。请告诉我如何设置隐藏字段。
-
在您的自动表单布局中使用
defaultValue请参阅github.com/aldeed/meteor-autoform#affieldinput -
谢谢@michel。当我使用 defaultValue 时,我仍然不确定如何访问其他用户 ID。我尝试从 {{id}} 引用 id,但这不起作用。有什么建议吗?
-
如何将其他用户带入模板?
标签: meteor meteor-collection2 simple-schema