NodesRef

Represents a reference to one or more UI nodes. It can be used to invoke UI methods, get and set properties on UI nodes.

NodesRef only saves the information needed to find nodes (such as CSS selectors), and does not actually reference a specific node. The actual node search is only carried out when SelectorQuery.prototype.exec() is executed. Therefore, the node that NodesRef reference may not actually exist. In this case, an error will be reported when exec() is called.

Instance Method

NodesRef.fields()

Query the attributes of the selected node.

NodesRef.invoke()

Execute the UI method of the selected node.

NodesRef.path()

Query the path information from the node to the root node of the page.

NodesRef.setNativeProps() .mdx)

Directly set the attributes of the selected node.

Examples

Obtain the position and size of the specified text node:

class Page extends Component {
  componentDidMount() {
    lynx
      .createSelectorQuery() // create SelectorQuery
      .select('#my-id') // Specify the selector of the target node
      .invoke({
        // Specify the operation for the target node
        method: 'boundingClientRect',
        success: function (res) {
          console.log(res);
        },
        fail: function (res) {
          console.log(res.code, res.data);
        },
      })
      .exec(); // Execute the query
  }

  render() {
    return (
      <view>
        <text id="my-id">...</text>
      </view>
    );
  }
}

Compatibility

Loading

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.