For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/lynx-api/selector-query.md.
Lynx
  • 简体中文
  • SelectorQuery BTS

    用于获得指定节点的引用,以便对其进行 UI 操作,例如调用其元件的方法、获取或设置节点属性。

    根据创建方式的不同,每个 SelectorQuery 对象都会被指定一个根节点。任何节点查找的范围都会被限制在该节点的叶子结点中。

    实例方法

    SelectorQuery.exec()

    执行所有已提交的 UI 节点操作任务。

    SelectorQuery.select()

    在 SelectorQuery 指定的根节点下选择第一个匹配指定 CSS 选择器的节点。

    SelectorQuery.selectAll()

    在 SelectorQuery 所指定的根节点下选择所有匹配指定 CSS 选择器的节点。

    SelectorQuery.selectRoot()

    选择 SelectorQuery 所指定的根节点。

    SelectorQuery.selectUniqueID()

    通过指定 uid 选择节点。

    示例

    获取指定 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 许可协议进行许可。