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 25, 2019Brass Contributor
So I made the following changes. I added the catch method and put another return in there but the IDE still doesn't think that my code always returns as a value.
protected fetchLists(): Array<IPropertyPaneDropdownOption> {
let 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++) {
if ((data[i].DefaultViewUrl.includes('/Lists/')) &&
(
(data[i].Title != 'SharePointHomeCacheList') ||
(data[i].Title != 'TaxonomyHiddenList')
)) {
options.push({
key: data[i].Title,
text: data[i].Title,
});
}
}
return options;
}).catch(function(e) {
return options;
});
}