目录

SelectorQuery

has.createSelectorQuery

has.createSelectorQuery(): SelectorQuery

Creates a SelectorQuery object instance.

In a custom component or a page that contains a custom component, use this.createSelectorQuery() instead.

Since: 1.0.0

Returns:

SelectorQuery object.

Example:

const query = has.createSelectorQuery();
query.select('#id').boundingClientRect();
query.exec(function(res) {
  console.info('res = ', res);
});

SelectorQuery

[h2]SelectorQuery.exec

SelectorQuery.exec(function callback): NodesRef

Executes all requests. The array of request results is constituted based on the request sequence and is returned in the first parameter of callback.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
callback function No Callback used to return the result.

Returns:

NodesRef object.

Example:

const query = has.createSelectorQuery();
const selecttarget = query.select('#movabletarget1').boundingClientRect(function(rect) {
  console.info('rect = ', rect);
}).exec();

[h2]SelectorQuery.in

SelectorQuery.in(Component component): SelectorQuery

Changes the selection scope of the selector to the custom component.

Initially, the selector selects only the nodes within the page.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
component Component Yes Custom component instance.

Returns:

SelectorQuery object.

Example:

const query = has.createSelectorQuery().in(this);

[h2]SelectorQuery.select

SelectorQuery.select(string selector): NodesRef

Selects the first node that matches the selector on the page. This API returns a NodesRef object instance, which can be used to obtain node information.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
selector string Yes Selector.

Returns:

NodesRef object.

Selector syntax

The selector is similar to a CSS selector, but only the following syntax is supported.

Example:

const query = has.createSelectorQuery();
const nodesRef = query.select('#movabletarget1');

[h2]SelectorQuery.selectAll

SelectorQuery.selectAll(string selector): NodesRef

Selects all nodes that match the selector on the page.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
selector string Yes Selector.

Returns:

NodesRef object.

Selector syntax

The selector is similar to a CSS selector, but only the following syntax is supported.

Example:

const query = has.createSelectorQuery();
const nodesRef = query.selectAll('#movabletarget1');

[h2]SelectorQuery.selectViewport

SelectorQuery.selectViewport(): NodesRef

Selects the display area. This API can be used to obtain the size and scrolling position of the display area.

Since: 1.0.0

Returns:

NodesRef object.

Example:

const query = has.createSelectorQuery();
const nodesRef = query.selectViewport();

NodesRef

[h2]NodesRef.boundingClientRect

NodesRef.boundingClientRect(function callback): SelectorQuery

Adds a request for querying the node layout position. The position is relative to the display area, in pixels. This API is similar to getBoundingClientRect of DOM.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
callback function No Callback used to return node information after the SelectorQuery.exec method is executed.

Return value of callback

Parameter Type Description
id string Node ID.
dataset object Dataset of a node.
left number Coordinates of the left margin of a node.
right number Coordinates of the right margin of a node.
top number Coordinates of the top margin of a node.
bottom number Coordinates of the bottom margin of a node.
width number Width of a node.
height number Height of a node.

Returns:

SelectorQuery object.

Example:

has.createSelectorQuery().select('#id').boundingClientRect(function(rect) {
  console.info('rect = ', rect);
}).exec();

[h2]NodesRef.context

NodesRef.context(function callback): SelectorQuery

Obtains the context object a node. Currently, VideoContext, CanvasContext, EditorContext, and MapContext can be obtained.

Since: 1.0.17

Parameters

Parameter Type Mandatory Description
callback function No Callback used to return node information after the SelectorQuery.exec method is executed.

Return value of callback

Parameter Type Description
context object Context object corresponding to the node.

Returns:

SelectorQuery object.

Example:

has.createSelectorQuery().select('#id').context(function(res) {
  console.info('context = ', res.context);
}).exec();

[h2]NodesRef.fields

NodesRef.fields(Object fields, function callback): SelectorQuery

Obtains the node information. You can specify the fields to be obtained in fields. The return value is the SelectorQuery corresponding to NodesRef.

Since: 1.0.17

Parameters

Parameter Type Mandatory Description
fields object Yes Options, including fields to be obtained.
callback function No Callback used to return the node information specified in fields after the SelectorQuery.exec method is executed.

fields

Parameter Type Default Value Mandatory Description
id boolean false No Whether to return the node ID.
dataset boolean false No Whether to return the node dataset.
rect boolean false No Whether to return the node layout position (left, right, top, and bottom).
size boolean false No Whether to return the node size (width and height).
scrollOffset boolean false No Whether to return the scrollLeft and scrollTop of the node. The node must be scroll-view or viewport.
properties Array<string> [] No List of specified property names. If this field is specified, the value of the property corresponding to the node is returned. (Only the values of common properties marked in the component document can be obtained. The values of id, class, style and properties bound to events cannot be obtained.)
computedStyle Array<string> [] No List of specified style names. If this field is specified, the value of the style corresponding to the node is returned.
context boolean false No Whether to return the context object corresponding to the node.
node boolean false No Whether to return the node instance corresponding to the node.

Returns:

SelectorQuery object.

Example:

has.createSelectorQuery().select('#id').fields({
  id: true,
  rect: true,
  size: true
}, function(res) {
  console.info('res = ', res);
}).exec();

[h2]NodesRef.node

NodesRef.node(function callback): SelectorQuery

Obtains the node instance. Currently, Canvas can be obtained.

Since: 1.0.17

Parameters

Parameter Type Mandatory Description
callback function No Callback used to return node information after the SelectorQuery.exec method is executed.

Return value of callback

Parameter Type Description
node object Node instance corresponding to the node.

Returns:

SelectorQuery object.

Example:

has.createSelectorQuery().select('#id').node(function(res) {
  console.info('node = ', res.node);
}).exec();

[h2]NodesRef.scrollOffset

NodesRef.scrollOffset(function callback): SelectorQuery

Obtains the scrolling position of a node. The unit is pixel. The node must be scroll-view or viewport. The SelectorQuery corresponding to NodesRef is returned.

Since: 1.0.17

Parameters

Parameter Type Mandatory Description
callback function No Callback used to return node information after the SelectorQuery.exec method is executed.

Return value of callback

Parameter Type Description
id string Node ID.
dataset object Dataset of a node.
scrollLeft number Horizontal scrolling position of a node.
scrollTop number Vertical scrolling position of a node.
scrollWidth number Scrolling width of a node.
scrollHeight number Scrolling height of a node.

Returns:

SelectorQuery object.

Example:

has.createSelectorQuery().selectViewport().scrollOffset(function(res) {
  console.info('res = ', res);
}).exec();