NodesRef.fields
Introduction
Retrieves relevant information about a node, with specific fields to be obtained specified in the fields
parameter. The return value is the selectorQuery
corresponding to the nodesRef
.
Parameters
Object fields, Function callback
Explanation of the fields
parameter
In the returned node information, the position of each node is described by the fields left
, right
, top
, bottom
, width
, and height
. If a callback function is provided, after executing the exec
method of selectQuery
, the node information will be returned in the callback.
Parameter Name | Type | Required | Default Value | Description |
---|---|---|---|---|
id | Boolean | No | Whether to return the node's id | |
dataset | Boolean | No | Whether to return the node's dataset | |
rect | Boolean | No | Whether to return the node's layout position (left, right, top, bottom) | |
size | Boolean | No | Whether to return the node's size (width, height) | |
scrollOffset | Boolean | No | Whether to return the node's scrollLeft and scrollTop; the node must be a scroll-view or a viewport | |
properties | Array.<string> | No | Specify a list of property names to return the current property values corresponding to the node (only regular attributes marked in the component documentation can be obtained, id, class, style, and event-bound attributes cannot be obtained) | |
computedStyle | Array.<string> | No | Specify a list of style names to return the current values corresponding to the node's style name |
Sample Code
Page({
data: {
NodesRefData: '',
},
queryNodeInfo() {
dlt
.createSelectorQuery()
.select('.scroll-view')
.fields(
{
id: false,
dataset: false,
rect: true,
size: true,
scrollOffset: true,
properties: ['scrollX', 'scrollY'],
computedStyle: ['margin', 'backgroundColor'],
},
(res) => {
console.log('Node Information', res);
this.setData({ NodesRefData: JSON.stringify(res) });
// res.dataset; // Node's dataset
// res.width; // Node's width
// res.height; // Node's height
// res.scrollLeft; // Node's horizontal scroll position
// res.scrollTop; // Node's vertical scroll position
// res.scrollX; // Current value of the node's scroll-x attribute
// res.scrollY; // Current value of the node's scroll-y attribute
// Returns the specified style name attributes here
// res.margin;
// res.backgroundColor;
}
)
.exec();
},
});