【问题标题】:Meteor Autoform - How can I show specific user data?Meteor Autoform - 如何显示特定的用户数据?
【发布时间】:2019-01-08 02:10:28
【问题描述】:

如果有人问过这个问题,请接受我的歉意,我确信它有,我同样确信这是我遗漏的小问题,没有正确理解。

我在本地运行以下https://autoform.meteorapp.com/updateaf

我专门使用 updateaf 表单...并安装了所有必需的软件包,即 accounts-passwords、accounts-ui 和 accounts-base。

我的问题是如何在此界面中显示名字、姓氏和年龄字段的用户特定数据?

目前,无论我以谁的身份登录,我得到的只是每次提交。

【问题讨论】:

    标签: meteor meteor-blaze meteor-accounts meteor-autoform meteor-useraccounts


    【解决方案1】:

    我对 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

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2015-04-03
      相关资源
      最近更新 更多