I have this simple function, that returns an array based on a condition:
const operationPerResource = (resource: ResourceTypes): OperationTypes[] => {
const operations = cases[resource] || cases.default;
return operations;
};
And I want to use that Function to iterate over an Array of Object with a {labe: string, value: string} type.
So, I create a simple map:
const resources = transformEnumToArray(ResourceTypes);
const operations = operationPerResource(resources[0].value).map((value: any) => ({
label: value,
value
}));
The above function gives the results only for the first item in the array. I want to iterate over all the items of the Array resources in our case, and depending on which one I choose, I get back the available operations.
THE PROBLEM:
I have a select-box. Each select-box is populated by resources. Every time, I select a resource, I want to print the correct output. So, I used the operationPerResource function to return the available operations for each resource:
But, the resources are an Array of Objects, so, I need to iterate over them, in order to get back the correct Operations every time:
exmaple:
Resource: Name1 => Operations for Name1[3 Items]
Resource: Name2 => Operations for Name2[2 Items]
Resource: Name3 => Operations for Name3[5 Items]
And so on and so on. If I click on a specific resoure I get back the expected results each time. I just want to make it dynamic..
I only want to print the results of each resource not all of the results together.
I am kinda stuck here. Any help will be appreciated.
mapon each element ofresources[0].valuetransfoerm byoperationPerResource? Is that what you need?operationPerResource(ResourceTypes.TheOneYouWant)?operationPerResourcewill return the correct array, each time. Basically, I want to iterate, to find the correct value.