Skip to content

Home > sculp-js > getPathById

getPathById() function

Retrieves the path (ancestors + self) for a given node ID.

Signature:

typescript
export declare function getPathById<V>(tree: ArrayLike<V>, nodeId: IdLike, options?: ITreeConf): [(number | string)[], any[]];

Parameters

Parameter

Type

Description

tree

ArrayLike<V>

Tree data

nodeId

IdLike

Target node ID

options

ITreeConf

(Optional) Configuration. Default: { childField = 'children', keyField = 'id' }

Returns:

[(number | string)[], any[]]

{[(number | string)[], V[]]} - Array of IDs and Array of Nodes from root to target

Released under the MIT License.