2 ms·
It occurs commonly any time you are dealing with nested data. For example: at work we deal with "roles" (professions), and underneath those there can be differ
by nicoburns 5y ago
It occurs commonly any time you are dealing with nested data.
For example: at work we deal with "roles" (professions), and underneath those there can be different specialisms. In some of our views we have filters that users can use to show a subset of the data. There is a filter for roles, and a filter for specialisms. But the specialisms filter should only show options that are relevant given the roles selected in the roles filter. So the code for generating the options to display in the specialisms filter dropdown is something like:
const availableSpecialisms = roles
.filter(role => selectedRoles.includes(role.id))
.flatMap(role => role.specialisms)