1

I want to get a sharepoint list and assign it to my list 'items' which of type is IExampleItem, but I don't really know how to do it; I tried the following code but it gives me an error, my list 'items' is not compatible with what my

closed as unclear what you're asking by Robert Lindgren, Ganesh Sanap, Gaurravs, Asad Refai, Hardik Sep 9 at 9:40

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0

_getFacItems return Promise《T》 so it not same as IExampleItem[].

I did sample test demo in my github project below, I bind data in component not in webpart directly, while it might be helpful for you.

https://github.com/OS-Lee/ReactSPFx/blob/master/src/webparts/reactSpFx/components/ReactSpFx.tsx

0

Check the type of 'items' in the FAQ component.

It must match with the return type of _getFacItems().

  • the problem i don't know which type return sp.web.lists.getByTitle("FAQ_List").items .select("Question", "Reponse","Categorie", "Langue") .orderBy("Created", true) .get() – khadi Aug 20 at 7:44
  • i change my code for this, but it doesn't work public _getFacItems() : IExampleItem[] { var ListFaq : IExampleItem[] ; debugger; sp.web.lists.getByTitle("FAQ_List").items .select("Question", "Reponse","Categorie/Title", "Langue") .expand("Categorie") .get() .then( response => { response.forEach( item => { ListFaq.push(item) }) }); ListFaq.forEach(item => { alert("khkjhkjhkhkhkjhkhj"+item.Question) }) debugger; return ListFaq; } – khadi Aug 20 at 9:25
0

Khadi,

While there is nothing technically wrong with loading the items in the FaqWebPart, I prefer to load it in the component for performance reasons. That way, it appears that the web part is faster (even if it isn't, really) by first rendering an empty list, and rendering a filled list once the items are loaded. You can even be fancy and add a 'loading' message, a spinner, or a shimmer to your list.

The trick to solve the error you get is to map the returned list items (which are of type any when they get returned) to a IFAQItem (or IExampleItem in your original code). In this example, assigned the returned items to a const variable to make it easier to read the code.

Here is how I would change the code to do this:

Full disclaimer: I did not build or run this code. There may be errors, but I should demonstrate the concept.

I hope this helps?

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