问题
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