Nodes class
📖 Description
The Nodes
class represents a collection of nodes of a form definition in the builder. Each node in the collection is a Node
instance.
🗃️ Fields
🏷️ all
Retrieves all the nodes that are in the collection.
Type
🏷️ count
Retrieves the number of nodes in the collection.
Type
number
🏷️ firstItem
Retrieves the first node in the collection.
Type
Node
| undefined
🏷️ lastItem
Retrieves the last node in the collection.
Type
Node
| undefined
🏷️ section
Retrieves the parent section.
Type
▶️ Methods
🔧 append
Appends a new node to the end of the collection.
Signature
append(): Node
Return value
Returns a reference to the new Node
instance.
🔧 each
Iterates through all nodes in the collection.
Signature
each(fn: (node: Node) => boolean | void): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn | (node: Node ) => boolean | void | No | Function that is called for each node in the collection. If you want to stop the iteration, you can return true from this function to do so. |
Return value
Returns true
if the iteration was stopped (break).
🔧 insert
Inserts a new node at the top of the collection.
Signature
insert(): Node
Return value
Returns a reference to the new Node
instance.
🔧 insertAfter
Inserts a new node after the supplied node.
Signature
insertAfter(node: Node): Node
Parameters
Name | Type | Optional | Description |
---|---|---|---|
node | Node | No | Specifies the node after which the new node is inserted. |
Return value
Returns a reference to the new Node
instance.
🔧 insertBefore
Inserts a new node before the supplied node.
Signature
insertBefore(node: Node): Node
Parameters
Name | Type | Optional | Description |
---|---|---|---|
node | Node | No | Specifies the node for which the new node is inserted. |
Return value
Returns a reference to the new Node
instance.
🔧 reverseEach
Iterates through all nodes in the collection in reverse direction (starting with the last node).
Signature
reverseEach(fn: (node: Node) => boolean | void): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn | (node: Node ) => boolean | void | No | Function that is called for each node in the collection. If you want to stop the iteration, you can return true from this function to do so. |
Return value
Returns true
if the iteration was stopped (break).
🔧 sort
Sorts the nodes using the supplied compare function.
Signature
sort(fn: (a: Node, b: Node) => number): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn | (a: Node , b: Node ) => boolean | No | Specifies the compare function. The compare function should return a number according to the following rules: - a is less than b return -1;- a is greater than b return 1;- a is equal to b return 0. |
Return value
Returns true
if the sort invoked a node position change.