Container.contains

Syntax

contains(item: PP.Ui.Control);

Parameters

item. Checked item.

Description

The contains method checks whether an item is in the container.

Comments

The method returns the True value, if the item is in the container, otherwise it is False.

Example

To execute the example, the HTML page must contain links to the PP.js script files and the PP.css styles file in the <body> tag of the HTML page of the <div> item with the gridPanel identifier. In the onload event of the <body> tag it is necessary to specify the call of the createGridPanel() function. Add a table with components on the page:

var container;
function createGridPanel() {
    // Create a table with components
    container = new PP.Ui.GridPanel({
        // Set parent item
        ParentNode: "gridPanel"
    });
    // Create 4 labels and add it in the table
    var label1 = new PP.Ui.Label({ Top: 0, Left: 0, Content: "Item 1" });
    var label2 = new PP.Ui.Label({ Top: 0, Left: 1, Content: "Item 2" });
    var label3 = new PP.Ui.Label({ Top: 1, Left: 0, Content: "Item 3" });
    var label4 = new PP.Ui.Label({ Top: 1, Left: 1, Content: "Item 4" });
    container.add(label1);
    container.add(label2);
    container.add(label3);
    container.add(label4);
}

Get the first item of the table:

// Get the first item of the table
var item = container.getLayoutItems()[0].getItems()[0];

Check whether the item is in the table:

// Check whether the item is in the table
if (container.contains(item) === true) {
    console.log("The item is in the table");
} else {
    console.log("The item is not in the table");
}

As a result the console displays the result of checking whether the item is in the table:

The item is in the table

 

Get the contents of all table items using the function:

// Get the contents of all table items using the function
var func = function (item) {
    console.log(item.getContent());
}
container.forEachElement(func);

As a result the contents of all table items is displayed in the console:

Item 1

Item 2

Item 3

Item 4

See also:

Container