Meteor AutoForm添加用户进行选择

时间:2016-12-06 15:56:22

标签: javascript meteor meteor-autoform

我知道我很接近这一点,但似乎无法理清我所缺少的东西。

我正在尝试将所有用户作为选项添加到autoform quickform中的select中。我能够使用另一个集合,但是当我为用户使用相同的代码时,值显示为_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打印到select。这是我现在的架构:

	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
	        };
	      });
	    }
	  }
	},

我很感激有人可以提供任何帮助!

1 个答案:

答案 0 :(得分:0)

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

	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
	        };
	      });
	    }
	  }
	},