Forum Discussion
smithme
Sep 25, 2019Brass Contributor
Webpart list property using PNPJS
I am writing a simple web part. It takes a property of "List". The user will pick the list from a dropdown. I am using the tutorial found here: https://www.sharepointnutsandbolts.com/2016/09/sharepo...
smithme
Sep 26, 2019Brass Contributor
This is what I am left with for now. My this.lists object is still empty before it gets to the PropertyPaneDropdown object and I don't know what to do to fix that.
protected fetchOptions(): IPropertyPaneDropdownOption[] {
var options: Array<IPropertyPaneDropdownOption> = new Array<IPropertyPaneDropdownOption>();
sp.web.lists.select('ID', 'Title', 'DefaultViewUrl').orderBy('Title').get().then(function(data){
for (let i = 0; i < data.length; i++) {
options.push({
key: data[i].Title,
text: data[i].Title
})
}
return options;
});
return null;
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
if (!this.lists) {
this.lists = this.fetchOptions();
this.onDispose();
}
return {
pages: [
{
header: {
description: this.description
},
groups: [
{
groupName: 'Properties',
groupFields: [
PropertyPaneDropdown('list', {
label: 'List',
options: this.lists
})
]
}
]
}
]
};
}