我对 updateaf 没有任何经验,但我对 Meteor 做了很多。
我假设您只想显示当前登录用户的信息并允许他们更新?
如果是这样,我想你会想要一个只发布当前用户信息的出版物(使用Meteor.userId(),你可能必须将 People 对象的 ._id 链接到 Meteor 用户 ID),然后拥有它自动选择数据。
从您提供的链接 (https://autoform.meteorapp.com/updateaf) 上的 Javascript 部分更改了部分:
原创(只显示与selectedPersonId相关的东西,其余的都在链接上):
Meteor.publish(null, function () {
return People.find();
});
Template.updateaf.helpers({
selectedPersonDoc() {
return People.findOne(Session.get("selectedPersonId"));
},
isSelectedPerson() {
return Session.equals("selectedPersonId", this._id);
}
});
Template.updateaf.events({
'click .person-row'() {
Session.set("selectedPersonId", this._id);
}
});
更改为(而不是显示所有用户并允许他们通过单击进行更改,只需返回与 Meteor 用户对应的单个用户)(您可能需要更改/删除一些其他 js 函数以摆脱“人列表”):
Meteor.publish(null, function () {
return People.findOne({ _id: Meteor.userId() );
});
Template.updateaf.helpers({
selectedPersonDoc() {
return People.findOne({ _id: Meteor.userId() );
}
});
如果您有任何问题,请告诉我,希望对您有所帮助。
如果您愿意,可以提供一些额外的教程:
https://guide.meteor.com/data-loading.html
https://themeteorchef.com/tutorials/publication-and-subscription-patterns