如何从流星数组中滤除特定元素?

时间:2019-07-07 16:54:33

标签: arrays sorting meteor

我正在尝试从仅包含数组特定元素的数组中获取响应。

端点代码

API.v1.addRoute('subscriptions.get', { authRequired: true }, {
    get() {
        const { updatedSince } = this.queryParams;

        let updatedSinceDate;
        if (updatedSince) {
            if (isNaN(Date.parse(updatedSince))) {
                throw new Meteor.Error('error-roomId-param-invalid', 'The "lastUpdate" query parameter must be a valid date.');
            } else {
                updatedSinceDate = new Date(updatedSince);
            }
        }

        let result;
        Meteor.runAsUser(this.userId, () => { result = Meteor.call('subscriptions/get', updatedSinceDate); });

        if (Array.isArray(result)) {
            result = {
                update: result,
                remove: [],
            };
        }

        return API.v1.success(result);
    },
});

输出

{
  "update": [
    {
      "t": "c",
      "ts": "2017-11-25T15:08:17.249Z",
      "name": "general",
      "fname": null,
      "rid": "GENERAL",
      "u": {
        "_id": "EoyAmF4mxx5HxJHJB",
        "username": "rocket.cat",
        "name": "Rocket Cat"
      },
      "open": true,
      "alert": true,
      "unread": 1,
      "userMentions": 1,
      "groupMentions": 0,
      "_updatedAt": "2017-11-25T15:08:17.249Z",
      "_id": "5ALsG3QhpJfdMpyc8"
    },
    {
      "t": "c",
      "ts": "2017-11-25T15:08:17.249Z",
      "name": "channel2",
      "fname": null,
      "rid": "CHANNEL2",
      "u": {
        "_id": "FoyAmF4mxx5HxJHJB",
        "username": "rocket.cat",
        "name": "Rocket Cat"
      },
      "open": true,
      "alert": true,
      "unread": 1,
      "userMentions": 1,
      "groupMentions": 0,
      "_updatedAt": "2017-11-25T15:08:17.249Z",
      "_id": "5ALsG3QhpJfdMpyc8"
    },
  ],
  "remove": [],
  "success": true
}

我只想要一个name元素列表。像这样:

{   “一般”,   “频道2” }

有关代码的更多详细信息,请在此处访问端点。请忽略更新的函数,因为这只是原始函数中的内容,而我在通道名称数组中将不需要它。如果有人能告诉我如何从结果数组中过滤此name元素,那将是很好的,因为流星的初学者无法弄清楚。谢谢。

0 个答案:

没有答案