Trying to get files from a SharePoint library and populate state React/SPFX

牧云@^-^@ 提交于 2021-01-29 14:22:03

问题


I am having trouble with populating state with files using the below code. The first getByTitle brings in the Id of the file but not the Name or CaseID column. The second getByName successfully brings in the name of the document, but how would I bring in the Id and the CaseID column as well?

 sp.web.lists.getByTitle("Case Documents").items.get().then((items: any[]) => { 
      let returnedItems: IListCItem[] = items.map((item) => { return new ListCItem(item); });

      this.setState({ 

        ListCItems: returnedItems, 
      });
    });

    sp.web.folders.getByName("Case Documents").files.get().then((files: any[]) => {
      let returnedItems: IListCItem[] = files.map((file) => { return new ListCItem(file); });

      this.setState({
        ListCFiles: returnedItems,
      });
    });

Here's the data model interface I'm using for the Doc library:

export interface IListCItem {

    Id: number;
    Name: string;
    CaseID: string;

}

export class ListCItem implements IListCItem {

    public Id: number;
    public Name: string;
    public CaseID: string;

    constructor(file: IListCItem){
        this.Id=file.Id;
        this.Name=file.Name;
        this.CaseID=file.CaseID;

    }
}

Any ideas? I'm thinking I need to use a spread operator to merge the two into the same state? Or is there an easier function from sp.web to use?

来源:https://stackoverflow.com/questions/60509591/trying-to-get-files-from-a-sharepoint-library-and-populate-state-react-spfx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!