Angular 6:如何基于简单数组创建新对象?

时间:2018-07-05 07:36:18

标签: typescript angular6

我必须基于一个数组实现一个动态菜单,以我拥有权限数组为例,并且登录的用户只能查看他具有数组权限的菜单,但是我的菜单有时具有多个下拉菜单或单个下拉菜单下。
我的示例代码为
模板中的默认菜单对象。
{ label: 'MENU', main: [ { arr_name: '', state: 'dashboard', short_label: 'D', name: 'Home', type: 'link', icon: 'ti-home' }, { arr_name: '', state: 'master', short_label: 'M', name: 'Master', type: 'sub', icon: 'ti-direction-alt', children: [ { arr_name: '', state: 'roles', name: 'Roles', type: 'sub', children: [ { arr_name: 'Add Role', state: 'add-roles', name: 'Add Roles', // target: true }, { arr_name: 'Edit Role', state: 'edit-roles', name: 'Edit Roles', // target: true } ] }, ] } ] }
我的权利数组是
["Add User", "Edit User", "Add Equipment", "Add Product", "Edit Product", "Approve Product", "System Setting", "View All Audit Trail", "Weighment", "Start/Stop Process", "Calibration", "Set Recalibration", "Clean Bin", "Add Role", "Edit Role", "Add Department", "View Report(Self)", "View All Report", "Reprint All Report", "Edit Equipment", "Verify Calibration Report", "Edit Cubicle", "Group Printable Report"]

在我的菜单对象中,如果权限数组中存在arr_name字段,那么我想基于该权限数组中的检查为菜单创建新对象。因此,用户只能看到他有权访问的菜单,谢谢。

0 个答案:

没有答案