【发布时间】:2022-06-30 17:08:47
【问题描述】:
我想按 ID 读取特定列表元素的值并将其显示在 SharePoint 网站上。
问题是我尝试使用 PNP 框架,但某些组件不再工作。 到目前为止,这是我的代码。 我希望你能帮助我。
import * as React from 'react';
import styles from './Webpartprojectsw.module.scss';
import { IWebpartprojectswProps } from './IWebpartprojectswProps';
import { escape } from '@microsoft/sp-lodash-subset';
import * as jquery from 'jquery';
import { IItemAddResult, DateTimeFieldFormatType } from "@pnp/sp/presets/all";
import { spfi, SPFI, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
export interface ISolypProjectListItemsState{
Title: string,
ID: number,
StartDate: string,
EndDate:string,
ProjectPhase: string,
TrafficLight:string,
message: string
}
export default class Webpartprojectsw extends
React.Component<IWebpartprojectswProps,ISolypProjectListItemsState> {
public static siteurl: string="";
public constructor(props:IWebpartprojectswProps, state: ISolypProjectListItemsState){
super(props);
this.state={
Title:"",
ID:0,
StartDate:"",
EndDate:"",
ProjectPhase:"",
TrafficLight:"",
message:""
};
Webpartprojectsw.siteurl= this.props.websiteurl;
}
public componentDidMount() {
this._ReadItem();
}
public render(): React.ReactElement<IWebpartprojectswProps> {
return (
<div>
{this.state.message}
{this.state.Title}
</div>
);
}
private async _ReadItem(){
// get a specific item by id
const item: any = await sp.web.lists.getByTitle("ProjectStatusList").items.getById(1).get();
console.log(item);
this.setState({message:"Last Item Created Title:--> " + item.Title + item.TrafficLight});
}
}
非常感谢!
马蒂亚斯
【问题讨论】:
-
您使用的是哪个版本的 PNP/SP?
-
我使用的是 PNP/JS 框架 3.0 版,但我认为他们改变了它。
标签: javascript reactjs sharepoint-online spfx pnp-js