new Loop()
- Description:
- A Loop is a collection of segments that are related to one another. In the example below, we create a loop starting from the W07 segment, and ending at the W20 segment. When you run a loop, it will find all segments between the W07 and W20 segments, and group them together.
- Source:
Example
const itemLoop = new Loop();
itemLoop.setPosition(0);
itemLoop.addSegmentIdentifiers(["W07", "N9", "W20"]);
transaction.addLoop(itemLoop);
transaction.runLoops();
Methods
toJSON() → {Object}
- Description:
- Returns a JSON representation of the Loop.
- Source:
Example
const json = loop.toJSON();
console.log(json);
// {
// position: 0,
// segmentIdentifiers: ["W07", "N9", "W20"],
// contents: [
// [
// {
// name: "W07",
// fields: [
// {
// content: "W07",
// },
// {
// content: "A",
// },
// {
// content: "1",
// }
// ],
// },
// {
// name: "N9",
// fields: [
// {
// content: "N9",
// },
// {
// content: "1",
// },
// {
// content: "A",
// }
// ],
// },
// ],
// [...],
// ],
// }
Returns:
-
Type
-
Object
(static) addSegmentIdentifier(segmentIdentifier) → {Loop}
- Description:
- Adds a segment identifier to the Loop.
- Source:
Examples
loop.addSegmentIdentifier("W07");
loop.addSegmentIdentifier("N9");
loop.addSegmentIdentifier("W20");
Parameters:
Name |
Type |
Description |
segmentIdentifier |
String
|
|
Returns:
-
Type
-
Loop
(static) addSegmentIdentifiers(segmentIdentifiers) → {Loop}
- Description:
- Adds segment identifiers to the Loop.
- Source:
Example
loop.addSegmentIdentifiers(["W07", "N9", "W20"]);
Parameters:
Name |
Type |
Description |
segmentIdentifiers |
Array.<String>
|
|
Returns:
-
Type
-
Loop
(static) getLastSegmentIdentifier() → {String}
- Description:
- Returns the last segment identifier in the Loop.
- Source:
Example
const lastSegmentIdentifier = loop.getLastSegmentIdentifier();
console.log(lastSegmentIdentifier);
// "W20"
Returns:
-
Type
-
String
(static) getPosition() → {Number}
- Description:
- Returns the position of the Loop.
- Source:
Example
const position = loop.getPosition();
console.log(position);
// 0
Returns:
-
Type
-
Number
(static) getSegmentIdentifiers() → {Array.<String>}
- Description:
- Returns the segment identifiers in the Loop.
- Source:
Examples
const segmentIdentifiers = loop.getSegmentIdentifiers();
console.log(segmentIdentifiers);
// ["W07", "N9", "W20"]
const [firstSegmentIdentifier, secondSegmentIdentifier, thirdSegmentIdentifier] = loop.getSegmentIdentifiers();
console.log(firstSegmentIdentifier);
// "W07"
console.log(secondSegmentIdentifier);
// "N9"
console.log(thirdSegmentIdentifier);
// "W20"
Returns:
-
Type
-
Array.<String>
(static) removeSegmentIdentifier(segmentIdentifier) → {Loop}
- Description:
- Removes a segment identifier from the Loop.
- Source:
Examples
loop.removeSegmentIdentifier("W07");
loop.removeSegmentIdentifier("N9");
loop.removeSegmentIdentifier("W20");
Parameters:
Name |
Type |
Description |
segmentIdentifier |
String
|
|
Returns:
-
Type
-
Loop
(static) setPosition(position) → {Loop}
- Description:
- Sets the position of the Loop.
- Source:
Example
loop.setPosition(0);
Parameters:
Name |
Type |
Description |
position |
Number
|
|
Returns:
-
Type
-
Loop