Skip to main content

find()

Description

Finds the item that corresponds to the specified parameters

Usage

find(rule: object): object;

// or

find(rule: function): object;

Parameters

  • rule - (required) the search criteria which can be specified:
    • as an object which contains the following parameters:
      • by: string | function - the search criterion (either the key of the item attribute or a search function)
      • match: string - the value of the item attribute
    • as a function: DataCallback(item: T, index?: number, array?: T[])

Returns

The method returns the first object of the item that matches the specified criteria

Example

const diagram = new dhx.Diagram("diagram_container", {
type: "default"
});
diagram.data.parse(data);

//searching for a shape by the attribute key
const shape = diagram.data.find({ by: "text", match: "Manager" });

//searching for a shape by the rule specified in the function
const shape = diagram.data.find((shape) => {
if(shape.text==="Manager"||shape.text==="Marketer"){return true}
});

Related articles: Finding the necessary item

Related sample: Diagram. Data. Finding necessary shape