使用Lodash对对象数组进行深度更新和删除操作

时间:2018-06-11 14:17:03

标签: javascript node.js lodash node-modules

我正在构建NodeJS应用程序,需要我使用这样的对象 -

var userObject = {
    userName: "jon",
    type: "user",
    active: true,
    category: null,
    userRelationships: [{ // one level deep array of Objects
            relationshipId: 121,
            relationshipStatus: "none",
            relationshipType: "colleague",
            lastUpdate: 2018 - 02 - 01,
            interactions: 0
        },
        {
            relationshipId: 12121,
            relationshipStatus: null,
            relationshipType: "colleague",
            lastUpdate: 2018 - 02 - 06,
            interactions: 0
        },
        ...
    ],
    userInteractions: [{
        interactionId: 121211,
        interactionStatus: "pending",
        owner: 12458,
        interactionDetails: [{ // two level deep array of Objects
                interactionDetailId: 754,
                parentInteractionId: 121211,
                detailsType: "interaction"

            },
            {
                interactionDetailId: 735,
                parentInteractionId: 121211,
                detailsType: "interaction"

            },
            ....
        ]
    }]
};

我正在使用lodash进行对象操作。我经常需要在一个对象数组中添加/删除/操纵属性,这些对象进一步嵌套到对象数组中,最后深达2级。 如何在不一次又一次编写for..infor..of循环的情况下实现此目的(使用lodash)? 我也对其他建议持开放态度。 谢谢

0 个答案:

没有答案