Adding Children

Rows are added to an outline by running the addChild() method on an instance of the Item class. In plainer terms, you append the addChild() method to a reference of an existing item, even the rootItem object.

DO THIS ►

Enter and run the following in the console:
row1 = rootItem.addChild()

The execution of the script will result in the creation of a new empty child of the targeted item, with a reference to the newly created item (child) returned from the action. In the example script, the resulting object reference will be stored in the variable titled: row1

console-entry-05 A new empty row in the outline

We can use the stored object reference to alter the text of the created row by assigning a text value (string) to the item’s topic property.

DO THIS ►

In the console, enter and run the following:
row1.topic = "How now brown cow."

console-entry-06

The text of the created row will be set to the entered value.

row-with-text

Add another row by repeating the previous steps, but with a new variable and text.

DO THIS ►

In the console, enter and run the following:
row2 = rootItem.addChild()
row2.topic = "The rain in Spain."

console-entry-07

A new row will be added at the end of the target item’s children, which is the default location for new entries, unless otherwise specified.

second-row

Optionally, you can specify the position for a new item (child), within the order of children of an item, by adding a insertion position as a parameter of the addChild() method. An insertion position for a new item is simply an object reference to an existing sibling of the new item, appended with either the terms before or after.

For example, a new item can be added at the start of a group of children rather than at the default end position.

DO THIS ►

In the console, enter and run the following:
row3 = rootItem.addChild(row1.before)
row3.topic = "Sunny days bring a haze."

console-entry-08

A new row will be added before the first row in the outline.

third-row

What’s Next?

In the next section (“Clean & Wax”) you’ll learn how to create and set the value for a new item in one line.

UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER