目录

Event Object

When a component triggers an event, the processing function bound to the logic layer receives an event object. The object contains the following fields.

Name

Type

Description

type

string

Event type.

timeStamp

integer

Timestamp when an event is generated.

target

object

Attribute value set of the component that triggers the event.

currentTarget

object

Attribute value set of the current component.

detail

object

Detailed information about the custom event object.

touches

array

Information array of touch points on the screen in a touch event.

changedTouches

array

Information array of touch points changed in a touch event.

target

Indicates the source component that triggers an event.

Name

Type

Description

id

string

ID of the component that triggers an event.

dataset

object

A set of custom attributes starting with data- in the component that triggers the event.

currentTarget

Indicates the current component bound to an event.

Name

Type

Description

id

string

ID of the component that triggers an event.

dataset

object

A set of custom attributes starting with data- in the component that triggers the event.

When view3 is tapped, the event objects target and currentTarget received by handleTap3 are view3, but that received by handleTap2 are view3 and view2 respectively.

dataset

You can define some custom data in the component node. When an event is triggered, the data is passed to the callback for processing.

In HXML, the custom data starts with data- or data, and multiple words are separated by hyphens (-). In this case, hyphens are replaced with the CamelCase style, and uppercase characters are automatically converted to lowercase characters. For example:

touches

touches is an array. Each element is a Touch object, indicating the touch point that currently stays on the screen.

[h2]Touch

Name

Type

Description

identifier

number

Identifier of a touch point.

pageX, pageY

number

Distance from the upper left corner of a document. The upper left corner is the origin, the horizontal axis is X, and the vertical axis is Y.

clientX, clientY

number

Distance from the upper left corner of the visible area (excluding the navigation bar) on the page. The horizontal axis is X, and the vertical axis is Y.

changedTouches

The data format of changedTouches is the same as that of touches. It indicates a changed touch point, for example, touchstart (a touch starts), touchmove (a touch moves), or touchend/touchcancel (a touch ends).

detail

Indicates custom event data. For details, see the definition of each event in the component definition.

In the details of a touch event, information with x and y represents the distance from the upper left corner of the document, the same as pageX and pageY.