1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| const
userPrefTest = { domain: [ { id: 1, label: 'domain1' }
, { id: 2, label: 'domain2' }
, { id: 3, label: 'domain3' }
]
, commodity: [ { id: 1, label: 'commodity1' }
, { id: 2, label: 'commodity2' }
, { id: 3, label: 'commodity3' }
, { id: 4, label: 'commodity4' }
]
}
,
projectTypeList = [ { id: 1
, label: 'pro1'
, domain: [ { id: 1, label: 'domain1' }, { id: 2, label: 'domain2' } ]
, commodity: [ { id: 1, label: 'com1' }, { id: 2, label: 'com2' } ]
}
, { id: 2
, label: 'pro2'
, domain: [ { id: 1, label: 'domain1' }, { id: 3, label: 'domain3' } ]
, commodity: [ { id: 1, label: 'com1' }, { id: 2, label: 'com2' }, { id: 4, label: 'com3' } ]
}
, { id: 3
, label: 'pro3'
, domain: [ { id: 4, label: 'domain4' }, { id: 5, label: 'domain5' } ]
, commodity: [ { id: 1, label: 'com1' } ]
}
]
;
const result = projectTypeList
.filter(elm=>elm.domain.reduce((test,dom)=>
(test||Boolean(userPrefTest.domain.find(ud=>ud.label===dom.label))),false))
console.log( result ) |
Partager