HomeDocs
Skip to main content

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 NameTypeRequiredDefault ValueDescription
idBooleanNoWhether to return the node's id
datasetBooleanNoWhether to return the node's dataset
rectBooleanNoWhether to return the node's layout position (left, right, top, bottom)
sizeBooleanNoWhether to return the node's size (width, height)
scrollOffsetBooleanNoWhether to return the node's scrollLeft and scrollTop; the node must be a scroll-view or a viewport
propertiesArray.<string>NoSpecify 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)
computedStyleArray.<string>NoSpecify 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();
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.