arrays - 使用 3 阵列检查能力
问题描述
我必须创建一个功能来检查能力和显示模块,这取决于能力。在每个模板中,我必须再次检查 subMobules 功能
我必须用结果对另一个数组进行排序
userAbilities 是这样的:
{ id: 1, name: 'moduleAuth1', title: 'moduleAuth1'},
{ id: 2, name: 'moduleAuth2', title: 'moduleAuth2'},
和我的模块:
[ {
name: 'module1',
auth: [moduleAuth1, moduleAuth2 ],
subModule: [
{
subName: 'foo',
subAuth: [subAuth1, subAuth2],
},
{
subName: 'foo2',
subAuth: [subAuth1, subAuth2, subAuth3],
},
{
name: 'module1',
auth: [moduleAuth1, moduleAuth2, moduleAuth3 ],
subModule: [
{
subName: 'foo',
subAuth: [moduleAuth1, moduleAuth2],
},
{
subName: 'foo2',
subAuth: [moduleAuth1],
},
}
]
这个函数需要等待用户的能力并返回一个数组,
我尝试使用 multi forEach 来做到这一点,但它真的很难阅读。
我唯一有效的功能,只测试一个身份验证,他不是异步的:
moduleFilter (module: any) {
const myStore = this.userAuth
const moduleFilter: any[] = []
module.forEach(moduleEl => {
if (moduleEl.auth[0] === true) {
moduleFilter.push(moduleEl)
}
myStore.forEach(userAuth => {
console.log(moduleEl.auth)
if (moduleEl.auth[0] === userAuth.name) {
moduleFilter.push(moduleEl)
}
})
})
console.log(moduleFilter)
return moduleFilter
}
解决方案
推荐阅读
- java - Java+Kotlin Android 项目中 Kotlin 文件中未解决的引用错误
- android - 使用 FileProvider 使用相机捕获图像,如何存储 uri
- java - How do assert one list in another list with same order
- virtualscroll - ionic 4虚拟滚动不起作用
- python - flask_restful 导入资源错误
- watson-conversation - 如何通过 Watson Assistant API 动态检索响应类型
- angular - 嵌套 in-memory-web-api 即更长的 uri
- vba - VBA:在不同的桌面 UI 比例下工作会导致不需要的自动缩放
- javascript - 谷歌地图使用 PHP、MySQL 显示错误的经度值
- c++ - 有没有办法用 AVX2 编写 _mm256_shldi_epi8(a,b,1) ?(向量之间每 8 位元素移位一位)