diff --git "a/zh-cn/application-dev/reference/apis-arkui/figures/getInspectorInfo\350\277\224\345\233\236\347\273\223\346\236\234$attrs\346\230\240\345\260\204\350\241\250.xlsx" "b/zh-cn/application-dev/reference/apis-arkui/figures/getInspectorInfo\350\277\224\345\233\236\347\273\223\346\236\234$attrs\346\230\240\345\260\204\350\241\250.xlsx" index c26d62fba0f599ce66004106e70ee1701d3d79aa..80515019c3c16a4f91e36255aac233b5581cb057 100644 Binary files "a/zh-cn/application-dev/reference/apis-arkui/figures/getInspectorInfo\350\277\224\345\233\236\347\273\223\346\236\234$attrs\346\230\240\345\260\204\350\241\250.xlsx" and "b/zh-cn/application-dev/reference/apis-arkui/figures/getInspectorInfo\350\277\224\345\233\236\347\273\223\346\236\234$attrs\346\230\240\345\260\204\350\241\250.xlsx" differ diff --git a/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md b/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md index 84d98a596e75d947a854f7e3b6c535cb878d7e46..1bd2283a86bca309f5bf8a0fa611d18dd3130b13 100644 --- a/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md +++ b/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md @@ -1388,21 +1388,23 @@ getFilteredInspectorTree(filters?: Array\): string | 参数名 | 类型 | 必填 | 说明 | | ------- | --------------- | ---- | ------------------------------------------------------------ | -| filters | Array\ | 否 | 需要获取的组件属性的过滤列表。目前仅支持过滤字段:
"id":组件唯一标识。
"src":资源来源。
"content":元素、组件或对象所包含的信息或数据。
"editable":是否可编辑。
"scrollable":是否可滚动。
"selectable":是否可选择。
"focusable":是否可聚焦。
"focused":是否已聚焦。
如果在filters参数中包含以上一个或者多个字段,则未包含的字段会在组件属性查询结果中被过滤掉。如果用户未传入filters参数或者filters参数为空数组,则以上字段全部不会在组件属性查询结果中被过滤掉。
从API version 20开始,支持该过滤字段:
"isLayoutInspector":是否显示自定义组件的属性。
其余字段仅供测试场景使用。 | +| filters | Array\ | 否 | 需要获取的组件属性的过滤列表。目前仅支持过滤字段:
"id":组件唯一标识。
"src":资源来源。
"content":元素、组件或对象所包含的信息或数据。
"editable":是否可编辑。
"scrollable":是否可滚动。
"selectable":是否可选择。
"focusable":是否可聚焦。
"focused":是否已聚焦。
如果在filters参数中包含以上一个或者多个字段,则未包含的字段会在组件属性查询结果中被过滤掉。如果用户未传入filters参数或者filters参数为空数组,则以上字段全部不会在组件属性查询结果中被过滤掉。
从API version 20开始,支持该过滤字段:
"isLayoutInspector":返回组件树是否包含[自定义组件](../../ui/state-management/arkts-create-custom-components.md)。如果用户未传入filters参数或者filters数组不包含isLayoutInspector,返回的组件树将缺少自定义组件的信息。
其余字段仅供测试场景使用。 | **返回值:** | 类型 | 说明 | | ------ | ---------------------------------- | -| string | 获取组件树及组件属性的JSON字符串。 | +| string | 获取组件树及组件属性的JSON字符串。组件中每个字段的含义请参考[getInspectorInfo](./js-apis-arkui-frameNode.md#getinspectorinfo12)的返回值说明。 | **错误码**: 以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 -| 错误码ID | 错误信息 | -| ------- | -------- | -| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | +| 错误码ID | 错误信息 | 处理建议 | +| ------- | -------- | -------- | +| 401 | invalid param count | 参数个数错误,确保传入的参数个数正确 | +| 401 | invalid param type | 参数类型错误,确保传入的参数类型正确 | +| 401 | get inspector failed | 查询结果出错。系统内部存在异常,需要联系华为工程师处理。 | **示例:** @@ -1490,22 +1492,25 @@ getFilteredInspectorTreeById(id: string, depth: number, filters?: Array\ | 否 | 需要获取的组件属性的过滤列表。目前仅支持过滤字段:
"id":组件唯一标识。
"src":资源来源。
"content":元素、组件或对象所包含的信息或数据。
"editable":是否可编辑。
"scrollable":是否可滚动。
"selectable":是否可选择。
"focusable":是否可聚焦。
"focused":是否已聚焦。
其余字段仅供测试场景使用。 | +| filters | Array\ | 否 | 需要获取的组件属性的过滤列表。目前仅支持过滤字段:
"id":组件唯一标识。
"src":资源来源。
"content":元素、组件或对象所包含的信息或数据。
"editable":是否可编辑。
"scrollable":是否可滚动。
"selectable":是否可选择。
"focusable":是否可聚焦。
"focused":是否已聚焦。
如果在filters参数中包含以上一个或者多个字段,则未包含的字段会在组件属性查询结果中被过滤掉。如果用户未传入filters参数或者filters参数为空数组,则以上字段全部不会在组件属性查询结果中被过滤掉。
其余字段仅供测试场景使用。 | **返回值:** | 类型 | 说明 | | ------ | -------------------------------------------- | -| string | 获取指定的组件及其子组件的属性的JSON字符串。 | +| string | 获取指定的组件及其子组件的属性的JSON字符串。组件中每个字段的含义请参考[getInspectorInfo](./js-apis-arkui-frameNode.md#getinspectorinfo12)的返回值说明。 | **错误码**: 以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 -| 错误码ID | 错误信息 | -| ------- | -------- | -| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | +| 错误码ID | 错误信息 | 处理建议 | +| ------- | -------- | -------- | +| 401 | invalid param count | 参数个数错误,确保传入的参数个数正确 | +| 401 | invalid param type | 参数类型错误,确保传入的参数类型正确 | +| 401 | invalid filter depth | depth参数需要大于或者等于0 | +| 401 | get inspector failed | 查询结果出错。如果传入的id不存在,接口会抛出此错误。请确保传入正确的组件id。 | **示例:** @@ -1514,6 +1519,43 @@ getFilteredInspectorTreeById(id: string, depth: number, filters?: Array\ +```ts +import { UIContext } from '@kit.ArkUI'; +@Entry +@Component +struct ComponentPage { + build() { + Column() { + Text("Hello World") + .fontSize(20) + .id("TEXT") + Button('getFilteredInspectorTreeById').onClick(() => { + const uiContext: UIContext = this.getUIContext(); + try { + let inspectorStr = uiContext.getFilteredInspectorTreeById('TEXT', 1); + console.log(`result1: ${inspectorStr}`); + inspectorStr = JSON.stringify(JSON.parse(inspectorStr)['$children'][0]); + console.log(`result2: ${inspectorStr}`); + } catch(e) { + console.log(`getFilteredInspectorTreeById error: ${e}`); + } + }) + } + .width('100%') + .height('100%') + } +} +``` +返回的JSON字符串结构如下: + +```ts +result1: {"$type":"root","width":"1260.000000","height":"2720.000000","$resolution":"3.250000","$children":[{"$type":"Text","$ID":6,"type":"build-in","$rect":"[457.00, 123.00],[804.00,199.00]","$debugLine":"","$attrs":{"borderStyle":"BorderStyle.Solid","borderColor":"#FF000000","borderWidth":"0.00vp","borderRadius":{"topLeft":"0.00vp","topRight":"0.00vp","bottomLeft":"0.00vp","bottomRight":"0.00vp"}}}]} +result2: {"$type":"Text","$ID":6,"type":"build-in","$rect":"[457.00, 123.00],[804.00,199.00]","$debugLine":"","$attrs":{"borderStyle":"BorderStyle.Solid","borderColor":"#FF000000","borderWidth":"0.00vp","borderRadius":{"topLeft":"0.00vp","topRight":"0.00vp","bottomLeft":"0.00vp","bottomRight":"0.00vp"}}} +``` +若需获取getFilteredInspectorTreeById方法中首个参数id指定的组件,须参照示例代码将getFilteredInspectorTreeById方法结果先转换为json对象,随后提取$children数组的首项。 + + ### getCursorController12+ getCursorController(): CursorController diff --git a/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-frameNode.md b/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-frameNode.md index 956e1378589845b49e15e5667dcec37926fb5ee1..a2028f5d84f19526b5d8f97e0c7d8312bca88e6c 100644 --- a/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-frameNode.md +++ b/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-frameNode.md @@ -1296,11 +1296,11 @@ getInspectorInfo(): Object 以查询Button组件节点为例获取到的Object结果部分值如下所示 ```json { - "$type": "Button", - "$ID": 44, - "type": "build-in", - "$rect": "[498.00, 468.00],[718.00,598.00]", - "$debugLine": "", + "$type": "Button", // 组件类型 + "$ID": 44, // 组件id + "type": "build-in", // build-in为系统组件,custom为自定义组件 + "$rect": "[498.00, 468.00],[718.00,598.00]", // 组件框左上角坐标和右下角坐标 + "$debugLine": "", // 组件对应源码的调试信息,包括源码路径和组件所在的行号。 "$attrs": { "borderStyle": "BorderStyle.Solid", "borderColor": "#FF000000",