我想在属性窗格中放置一个下拉列表:
PropertyPaneChoiceGroup('Marvels', {
label: "Marvels",
options: [
{ key: 'Hulk', text: 'Hulk' },
{ key: 'Thor', text: 'Thor' },
{ key: 'Captain America', text: 'Captain America' },
{ key: 'Ironman', text: 'Ironman' } ,
],
})
我想做的是改为遍历一组名称:
let marvelNames: string[] = ["Hulk", "Thor", "Cap", "Iron"];
PropertyPaneChoiceGroup('Marvels', {
label: "Marvels",
options: [
for (let name in marvelNames) {
{ key: "name", text: "name" }
}
],
})
我不知道该如何实现。
我现在只在JS / TS上工作了几周,还有很多东西要学习。
答案 0 :(得分:2)
您需要填充以下值:
let marvelNames: string[] = ["Hulk", "Thor", "Cap", "Iron"];
var characters: IPropertyPaneChoiceGroupOption[] = [];
marvelNames.map(function(item){
characters.push({
key:item,
text: item
})
});
将属性窗格修改为:
PropertyPaneChoiceGroup('Marvels', {
label: "Marvels",
options: characters
})
此外,请确保您具有正确的import语句,其中包含IPropertyPaneChoiceGroupOption
的形式如下:
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField,
PropertyPaneChoiceGroup,
IPropertyPaneChoiceGroupOption
} from '@microsoft/sp-webpart-base';