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/nodes-ref-path.md.
Lynx
  • 简体中文
  • NodesRef: path() method

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

    语法

    path(callback: (data: object, status: object) => void): SelectorQuery;

    参数

    callback

    一个回调函数,查询结果将作为回调函数的参数返回。回调函数有两个参数:

    第一个参数返回查询结果。

    • 如果该 NodesRef 表示一个节点,则返回包含查询结果的 Record<string, any> 对象。如果节点未找到,则返回 null
    • 如果该 NodesRef 表示多个节点,则返回一个 Record<string, any> 对象的数组,数组内的每一个元件对应一个节点的查询结果。如果节点均未找到,则返回空数组。

    第二个参数返回查询的状态(错误信息)。

    返回值

    包含了该任务的 SelectorQuery 对象。调用 exec() 来执行任务。

    示例

    lynx
      .createSelectorQuery()
      .select('#target')
      .path((res, status) => {
        console.log(JSON.stringify(res));
        console.log(JSON.stringify(status));
      })
      .exec();

    可能的输出:

    // res
    {
        // array from target to root
        "path":
        [
            {
                tag:"",
                id:"",
                class:[],
                dataSet:{},
                // index of parent's children
                index:0,
            },
            ...
            {
                tag:"page",
                id:"",
                class:[],
                dataSet:{},
                index:0,
            }
        ]
    }
    
    // status
    {
      "data": "succeed",
      "code": 0
    }

    兼容性

    LCD tables only load in the browser

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