I am using spfx with react framework/pnp-js.t In a form I have total 8 dropdowns.I want to render data to these fields from 8 different sharepoint lists through one function only.
I tried implementing this thing for one drodown say 'City'. But stuck in using the same function for rest of 7 dropdowns. I understand that we can pass a listName dynamically while calling a function but how to dynamically store the data retrived to different constants or arrays.
const locoptions: IDropdownOption[] = [
{ key: 'city', text: 'City', itemType: DropdownMenuItemType.Header }
];
<Dropdown label="City" defaultSelectedKey="Pune" required={true}
options={locoptions} styles={dropdownStyles} />
public componentWillMount()
{
this.getDropdownData('Cities');
}
public getDropdownData(listName:string)
{
sp.web.lists.getByTitle(listName).items.get().then((items: any[]) =>
{
for(let i=0;i<items.length;i++)
{
locoptions.push({
key: items[i].Id,
text: items[i].Title
});
}
});
}