getCurrentItem( )
Returns the current item.
Description
The getCurrentItem()
function returns an object whose key:value pairs
are the field keys and field values of the current item, including all
hidden fields. Fields that do not have a value are omitted from the
returned object.
When called on a write-only or read & write dataset,
getCurrentItem()
returns the unsaved state of the current item.
Returns null
or undefined
if the dataset:
- Is filtered to not match any items in the collection.
- Is empty.
- Has not loaded yet.
Note:
A dataset needs to load its data before you call its
getCurrentItem()
function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you callgetCurrentItem()
inside the page’sonReady()
event handler, the dataset might not be ready yet.To call
getCurrentItem()
as soon as possible after a page loads, use the dataset'sonReady()
function inside the page’sonReady()
event handler to ensure that both the page and the dataset have finished loading.If the current item is changed from a non-dataset source, such as by selecting a row in a table connected to a dataset or clicking a button set to advance to the next item in a dataset, the dataset's current item is not updated immediately. Therefore, to get the dataset's new current item, call
getCurrentItem()
in the dataset'sonCurrentIndexChanged()
event handler. Do not use the events of the non-dataset source, such asonRowSelect
oronClick
, to callgetCurrentItem()
because they will fire before the dataset's current item is updated.
Syntax
function getCurrentItem(): Object
getCurrentItem Parameters
This function does not take any parameters.
Returns
The current item, or null if there is no current item.
Return Type:
Related Content:
Was this helpful?
1let itemObj = $w("#myDataset").getCurrentItem();23/*4 * {5 * "_id": "fcec780a-3e37-4b64-8a66-37c552c53f99",6 * "_owner": "f6c0f9c3-a62d-7e9f-g58d-943829af244d9",7 * "_createdDate": "2017-05-01T17:19:03.823Z",8 * "_updatedDate": "2017-05-01T17:19:10.477Z",9 * "title": "Dr. ",10 * "name": "B",11 * "link-dynamic-name": "/myCollection/B"12 * }13 */
1$w.onReady( () => {2 $w("#myDataset").onReady( () => {3 let itemObj = $w("#myDataset").getCurrentItem();45 } );67} );89/* itemObj:10 *11 * {12 * "_id": "fcec780a-3e37-4b64-8a66-37c552c53f99",13 * "_owner": "f6c0f9c3-a62d-7e9f-g58d-943829af244d9",14 * "_createdDate": "2017-05-01T17:19:03.823Z",15 * "_updatedDate": "2017-05-01T17:19:10.477Z",16 * "title": "Dr. ",17 * "name": "B",18 * "link-dynamic-name": "/myCollection/B"19 * }20 */
This example demonstrates how to get an item's details using the at()
function. We use this
function to establish context when a repeater container is clicked.
1$w.onReady( function () {2 $w("#repeatedContainer").onClick( (event) => {3 let $item = $w.at(event.context);4 let clickedItemData = $item("#myDataset").getCurrentItem();5 } );6} );