0
let permissions = [
    {
        id: 1,
        name: "Inventory",
        permission: "inventory"
    },
    {
        id: 2,
        name: "Inventory read",
        permission: "inventory:read"
    },
    {
        id: 3,
        name: "Purchase Orders",
        permission: "purchase-orders"
    },
    {
        id: 4,
        name: "Purchase Orders create",
        permission: "purchase-orders:create"
    }
];


let roles = [
    {
        id: 1,
        name: "Admin"
    },
    {
        id: 2,
        name: "Manager"
    }
];

我需要有一组权限按“权限”的第一部分分组,这些权限具有权限名称和角色的属性,每个都具有分组权限

最初,我通过推送到 groups[permission.split(':')] 来对权限进行分组,然后循环访问权限并在循环内循环我的模板中的角色。

我现在需要先构建数据。

我需要以下输出:

let list = [
{
    permission: 'Inventory',
    Admin: [
        {
            id: 1,
            name: "Inventory",
            permission: "inventory"
        },
        {
            id: 2,
            name: "Inventory read",
            permission: "inventory:read"
        },
    ],
    Manager: [
        {
            id: 1,
            name: "Inventory",
            permission: "inventory"
        },
        {
            id: 2,
            name: "Inventory read",
            permission: "inventory:read"
        },
    ]
},
{
    permission: 'Purchase Orders',
    Admin: [
        {
            id: 3,
            name: "Purchase Orders",
            permission: "purchase-orders"
        },
        {
            id: 4,
            name: "Purchase Orders create",
            permission: "purchase-orders:create"
        }
    ],
    Manager: [
        {
            id: 3,
            name: "Purchase Orders",
            permission: "purchase-orders"
        },
        {
            id: 4,
            name: "Purchase Orders create",
            permission: "purchase-orders:create"
        }
    ]
}

];

4

0 回答 0