How to Retrieve data from SharePoint list via PnP JS Core and CAML Query
-
15-02-2021 - |
Question
As I am new to SharePoint framework, I am using PnP JS core library in SharePoint webpart,please suggest how can I retrieve list items from SharePoint list via PnP JS core and CAML Query.
Please suggest any workaround for the same.
La solution
You can get items from SharePoint list using a CAML Query.
Sample Code:
import { ICamlQuery } from "@pnp/sp/lists";
// build the caml query object (in this example, we include Title field and limit rows to 5)
const caml: ICamlQuery = {
ViewXml: "<View><ViewFields><FieldRef Name='Title' /></ViewFields><RowLimit>5</RowLimit></View>",
};
// get list items
const r = await list.getItemsByCAMLQuery(caml);
// log resulting array to console
console.log(r);
References:
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange