【问题标题】:Meteor AutoForm adding users to selectMeteor AutoForm 添加用户选择
【发布时间】:2017-04-21 08:10:10
【问题描述】:

我知道我对此很接近,但似乎无法理清我缺少的东西。

我正在尝试将所有用户作为选项添加到自动生成快速表单中的选择中。我能够让它与另一个集合一起使用,但是当我为用户使用相同的代码时,值显示为 _id 但我无法让标签返回。

这是我的用户结构:

{
  "_id": "s3EYXXK5N8NExHrke",
  "emails": [{
    "address": "admin@gmail.com",
    "verified": false
  }],
  "profile": {
    "firstName": "Joe",
    "lastName": "Smuck",
    "licenseNumber": "1234567",
    "accountType": "administrator"
  },
  "roles": [
    "administrator"
  ],
  "createdAt": "2016-12-02T21:51:11.844Z",
  "services": {
    "password": {
      "bcrypt": "$2a$10$NheMU2x/8RvcMxNHeWxbQOpHlWAQmopvk3KrMG9oo5ruTir2ARf8W"
    },
    "resume": {
      "loginTokens": [{
        "when": "2016-12-02T21:51:11.948Z",
        "hashedToken": "8PktpX6kqK6yM+LMrqRaoqXCbwYG6gdO7MH9V/Th/dI="
      }, {
        "when": "2016-12-03T03:01:06.600Z",
        "hashedToken": "ihn93xaN6rE8fvwBHZ3p8H6z0T7o7WChQoqD4dlkSpw="
      }, {
        "when": "2016-12-05T14:37:41.147Z",
        "hashedToken": "7QE7HxcmDrZPFI3Omn5c1o73pMa3XzOBj3RbquCmo6U="
      }]
    }
  }
}

我正在尝试将 firstName 打印到选择中。这是我现在拥有的架构:

	inspector: {
	  type: String,
	  label: "Inspector",
	  autoform: {
	    firstOption: 'Choose an Inspector',
	    options: function() {
	      return Meteor.users.find({}, {
	        sort: {
	          profile: 1,
	          firstName: 1
	        }
	      }).map(function(c) {
	        return {
	          label: c.firstName,
	          value: c._id
	        };
	      });
	    }
	  }
	},

如果有人能提供任何帮助,我将不胜感激!

【问题讨论】:

  • 但是...firstNameprofile 之下。
  • 对不起,我对 Meteor 有点陌生,我该怎么写?会是 c.profile.firstName 吗?
  • 没关系,大声笑应该在我发布之前测试过!谢谢你让我检查!哈哈

标签: javascript meteor meteor-autoform


【解决方案1】:

为了解决这个问题,它应该是:

	inspector: {
	  type: String,
	  label: "Inspector",
	  autoform: {
	    firstOption: 'Choose an Inspector',
	    options: function() {
	      return Meteor.users.find({}, {
	        sort: {
	          profile: 1,
	          firstName: 1
	        }
	      }).map(function(c) {
	        return {
	          label: c.profile.firstName,
	          value: c._id
	        };
	      });
	    }
	  }
	},

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 2015-05-08
    • 2017-10-05
    • 1970-01-01
    • 2015-01-31
    • 2015-09-22
    • 1970-01-01
    • 2016-01-30
    相关资源
    最近更新 更多