代码之家  ›  专栏  ›  技术社区  ›  Peter

计算vue对象中的项

  •  1
  • Peter  · 技术社区  · 5 年前

    我想知道有多少东西有价值 material_delivery 1 ?

    我喜欢在 vue method .

    [{
        "id": 43,
        "uuid": "c92421d0-71cc-433d-b7b5-fc6c91c2a3a4",
        "project_id": 8,
        "name": "Konstruktionsfreigabe",
        "due_date": "2019-10-18",
        "material_delivery": 0,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-31 13:09:41"
    }, {
        "id": 44,
        "uuid": "a063964b-f8fc-4c28-9055-09ed5fc4b8dd",
        "project_id": 8,
        "name": "Material",
        "due_date": "2019-12-13",
        "material_delivery": 1,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-31 13:06:37"
    }, {
        "id": 45,
        "uuid": "7de3410f-82c2-4b30-8e69-56906b16da4b",
        "project_id": 8,
        "name": "Montageende",
        "due_date": "2019-12-16",
        "material_delivery": 0,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-30 16:43:04"
    }, {
        "id": 46,
        "uuid": "8b034697-543c-46f6-a5be-104011700fb9",
        "project_id": 8,
        "name": "Lieferung",
        "due_date": "2020-01-25",
        "material_delivery": 1,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-31 13:57:16"
    }, {
        "id": 47,
        "uuid": "ec1101cf-97cc-4eed-a2c6-0685b7cc073b",
        "project_id": 8,
        "name": "Abnahme",
        "due_date": "2020-03-05",
        "material_delivery": 0,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-30 16:43:04"
    }, {
        "id": 48,
        "uuid": "deb7324a-64f2-4e1c-a358-87fdb95430ea",
        "project_id": 8,
        "name": "Rechnung",
        "due_date": "2020-04-14",
        "material_delivery": 0,
        "closed_at": null,
        "closed_from": null,
        "deleted_at": null,
        "created_at": "2019-12-30 16:43:04",
        "updated_at": "2019-12-30 16:43:04"
    }]
    
    

    我试过过滤,但没有成功。

    最后,我想知道,如果有多个项目的值为1 材料交付

    1 回复  |  直到 5 年前
        1
  •  1
  •   T. Short    5 年前

    有很多方法可以做到这一点。你可以用 filter ,就像你最初尝试的那样:

    methods: {
        countMaterialDelivery(array) {
            return array.filter(item => item.material_delivery === 1).length;
        }
    }