我的 ReactJs SPFx 共享点在线 Web 部件中有以下类型脚本:-
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
IPropertyPaneDropdownOption,
PropertyPaneDropdown} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'ContactListWebPartStrings';
import ContactListApp from './components/ContactListApp';
import { IContactListProps } from './components/IContactListProps';
import { sp } from "@pnp/sp/presets/all";
export interface IContactListWebPartProps {
department: string;
}
export default class ContactListWebPart extends BaseClientSideWebPart<IContactListWebPartProps> {
private viewModeOptions: IPropertyPaneDropdownOption[] = null;
public render(): void {
const element: React.ReactElement<IContactListProps> = React.createElement(
ContactListApp,
{
department: this.properties.department,
context: this.context
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
public onInit(): Promise<void> {
return super.onInit().then( _ => {
sp.setup({
spfxContext: this.context
});
const choice =
sp.web.lists.getByTitle('Contacts').fields.getByTitle('Department').get();
this.viewModeOptions = choice.Choices.map((choice: string, idx: number) =>
{
return {
key: idx,
text: choice
}
})
});
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneDropdown('department', {
label: 'Department',
options: this.viewModeOptions,
selectedKey: this.viewModeOptions[0].key,
disabled: !this.viewModeOptions
}),
]
}
]
}
]
};
}
}
但我收到此错误choice.Choices.map
:-
“承诺”类型上不存在属性“选择”