Search.../

getItems( )

Returns the selected items.

Description

The getItems() function returns a Promise that is resolved to a GetItemsResult object when the items have been retrieved.

Calling getItems() on a write-only dataset causes an error.

Note:

A dataset needs to load its data before you call its getItems() function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call getItems() inside the page’s onReady() event handler, the dataset might not be ready yet.

To call getItems() as soon as possible after a page loads, use the dataset's onReady() function inside the page’s onReady() event handler to ensure that both the page and the dataset have finished loading.

Syntax

function getItems(fromIndex: number, numberOfItems: number): Promise<GetItemsResult>

getItems Parameters

NAME
TYPE
DESCRIPTION
fromIndex

number

The index of the first item to return.

numberOfItems

number

The number of items to return.

Returns

Fulfilled - The items retrieved and the total number of items in the dataset that match its filter criteria. Rejected - An error object.

Return Type:

Promise<GetItemsResult>
Mixed in from:wix-dataset.Dataset

Related Content:

Was this helpful?

Get items from the dataset

Code Example

Copy Code
1$w("#myDataset").getItems(3, 2)
2 .then( (result) => {
3 let items = result.items;
4 let totalCount = result.totalCount;
5 let offset = result.offset;
6 } )
7 .catch( (err) => {
8 let errMsg = err.message;
9 let errCode = err.code;
10 } );
Get items from the dataset when the page loads

Code Example

Copy Code
1$w.onReady( () => {
2 $w("#myDataset").onReady( () => {
3 $w("#myDataset").getItems(3, 2)
4 .then( (result) => {
5 let items = result.items;
6 let totalCount = result.totalCount;
7 let offset = result.offset;
8 } )
9 .catch( (err) => {
10 let errMsg = err.message;
11 let errCode = err.code;
12 } );
13
14 } );
15
16} );