> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# NodesRef

APISummary
表示对一个或多个 UI 节点的引用。可用来对 UI 节点进行方法调用、属性获取和设置。

`NodesRef` 内部只保存查找节点所需的信息（例如 CSS 选择器），并不真正地指向某一个特定节点。实际的节点查找在 `SelectorQuery.prototype.exec()` 执行时才进行。
因此，`NodesRef` 指向的节点可能实际并不存在。在这种情况下，会在 `exec()` 调用时报错。

## 实例方法

[`NodesRef.fields()`](/next/zh/api/lynx-api/nodes-ref/nodes-ref-fields.md)

查询选定节点的属性。

[`NodesRef.invoke()`](/next/zh/api/lynx-api/nodes-ref/nodes-ref-invoke.md)

执行选定元件的方法。

[`NodesRef.path()`](/next/zh/api/lynx-api/nodes-ref/nodes-ref-path.md)

查询节点到页面根节点的路径信息。

[`NodesRef.setNativeProps()`](/next/zh/api/lynx-api/nodes-ref/nodes-ref-set-native-props.md)

直接设定选定节点的属性。

## 示例

获取指定 `text` 节点的位置和大小：

```tsx
class Page extends Component {
  componentDidMount() {
    lynx
      .createSelectorQuery() // 创建 SelectorQuery
      .select('#my-id') // 指定目标节点的选择器
      .invoke({
        // 指定对目标节点的操作
        method: 'boundingClientRect',
        success: function (res) {
          console.log(res);
        },
        fail: function (res) {
          console.log(res.code, res.data);
        },
      })
      .exec(); // 执行查询
  }

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

## 兼容性

**Compatibility Table**

**Query:** `lynx-api.nodes-ref.NodesRef`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/NodesRef.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| NodesRef | Yes (2.2) | Yes (3.4) | Yes (2.2) | Yes (3.7) | Yes (3.7) | Partial |
| &#96;fields&#96; | Yes (2.8) | Yes (3.4) | Yes (2.8) | Yes (3.7) | Yes (3.7) | No |
| &#96;invoke&#96; | Partial (2.2) | Partial (3.4) | Partial (2.2) | Partial (3.7) | Partial (3.7) | Partial |
| &#96;path&#96; | Yes (2.8) | Yes (3.4) | Yes (2.8) | Yes (3.7) | Yes (3.7) | Yes |
| &#96;setNativeProps&#96; | Yes (2.3) | Yes (3.4) | Yes (2.3) | Yes (3.7) | Yes (3.7) | Yes |

**`NodesRef`**

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

- **Web — Supported (version unknown):** Partial support; Supports invoke, path, and setNativeProps. The fields query is not implemented.

**`` `fields` ``**

Query the attributes of the selected node.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/NodesRef.json) · [API Reference](/next/api/lynx-api/nodes-ref/nodes-ref-fields)

- **Web — Not supported:** The Web background runtime does not implement NativeApp.getFields.

**`` `invoke` ``**

Execute the UI method of the selected node.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/NodesRef.json) · [API Reference](/next/api/lynx-api/nodes-ref/nodes-ref-invoke)

- **Android — From 2.2:** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.proptotype.selectAll()`.
- **HarmonyOS — From 3.4:** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.proptotype.selectAll()`.
- **iOS — From 2.2:** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.proptotype.selectAll()`.
- **macOS — From 3.7:** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.proptotype.selectAll()`.
- **Windows — From 3.7:** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.proptotype.selectAll()`.
- **Web — Supported (version unknown):** Partial support; Does not support usage on `NodesRef` created through `SelectorQuery.prototype.selectAll()`.

**`` `path` ``**

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

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/NodesRef.json) · [API Reference](/next/api/lynx-api/nodes-ref/nodes-ref-path)

**`` `setNativeProps` ``**

Directly set the attributes of the selected node.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/nodes-ref/NodesRef.json) · [API Reference](/next/api/lynx-api/nodes-ref/nodes-ref-set-native-props)

