0

I use PnP for getting SharePoint list item. But I don't really know, how use the result of my function.

I wish to get items of my SharePoint list using PnP and assign it to my list.

My code don't work:

  public render(): void {

    const element: React.ReactElement<IFaqProps > = React.createElement(
      Faq,
      {
        description: this.properties.description,
        items :  this.getFaqList()
        }
    );

    ReactDom.render(element, this.domElement);
  }

    let ListFaq : IExampleItem[];
/*= [{Question:"question",Reponse:"response", Categorie :{Title : "SharePoint"} , Langue:"fr"},
{Question:"question",Reponse:"response", Categorie :{Title : "OnDrive"} , Langue:"fr"}];*/

this._getListData()
       .then((response) => {
         response.forEach((item: IExampleItem) => {
           alert(item.Question);
          return ListFaq.push(item);
         });
 });
return ListFaq;
}

   public _getListData(): Promise<IExampleItem[]> {
    return sp.web.lists.getByTitle("FAQ_List").items
    .select("Question", "Reponse","Categorie/Title", "Langue")
    .expand("Categorie")
    .get()
    .then((response) => {

       return response;
     });

    }
export interface IFaqProps {
  description: string;
  items: IExampleItem[];
}
export type IExampleItem = { Question: string; Reponse: string; Categorie: {Title :string}; Langue: string };
0

Debug your code - set a breakpoint on return response; then check the result inside of response object. Add another then to your promise i.e. .then((items) => { console.log(items);}) then do whatever you want with the data in your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.