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, and this page is available as Markdown at /next/zh/api/lynx-api/nodes-ref.md.
Lynx
  • 简体中文
  • NodesRef BTS

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

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

    实例方法

    NodesRef.fields()

    查询选定节点的属性。

    NodesRef.invoke()

    执行选定元件的方法。

    NodesRef.path()

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

    NodesRef.setNativeProps()

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

    示例

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

    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>
        );
      }
    }

    兼容性

    LCD tables only load in the browser

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。