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.

Était-ce utile?

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:

  1. Get list items using a CAML Query
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top