提交 c4c91b97 编写于 作者: Z zaki

fix sample code problems in accessibility docs

Signed-off-by: Nzaki <zhoujun141@huawei.com>
Change-Id: Idf1970f0033252f02cb403a52551fad072594c20
上级 5c1b453a
...@@ -64,6 +64,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;): ...@@ -64,6 +64,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;):
**示例:** **示例:**
```ts ```ts
import accessibility from '@ohos.accessibility';
let name = 'com.ohos.example/axExtension'; let name = 'com.ohos.example/axExtension';
let capability : accessibility.Capability[] = ['retrieve']; let capability : accessibility.Capability[] = ['retrieve'];
try { try {
...@@ -105,6 +106,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, c ...@@ -105,6 +106,7 @@ enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, c
**示例:** **示例:**
```ts ```ts
import accessibility from '@ohos.accessibility';
let name = 'com.ohos.example/axExtension'; let name = 'com.ohos.example/axExtension';
let capability : accessibility.Capability[] = ['retrieve']; let capability : accessibility.Capability[] = ['retrieve'];
try { try {
......
...@@ -210,6 +210,7 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -210,6 +210,7 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:** **示例:**
```ts ```ts
let focusElement;
try { try {
axContext.getFocusElement((err, data) => { axContext.getFocusElement((err, data) => {
if (err) { if (err) {
...@@ -242,6 +243,7 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib ...@@ -242,6 +243,7 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib
**示例:** **示例:**
```ts ```ts
let focusElement;
try { try {
axContext.getFocusElement(isAccessibilityFocus, (err, data) => { axContext.getFocusElement(isAccessibilityFocus, (err, data) => {
if (err) { if (err) {
...@@ -324,6 +326,7 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -324,6 +326,7 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:** **示例:**
```ts ```ts
let rootElement;
try { try {
axContext.getWindowRootElement((err, data) => { axContext.getWindowRootElement((err, data) => {
if (err) { if (err) {
...@@ -364,6 +367,7 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle ...@@ -364,6 +367,7 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle
**示例:** **示例:**
```ts ```ts
let rootElement;
try { try {
axContext.getWindowRootElement(windowId, (err, data) => { axContext.getWindowRootElement(windowId, (err, data) => {
if (err) { if (err) {
...@@ -536,10 +540,11 @@ injectGesture(gesturePath: GesturePath): Promise\<void>; ...@@ -536,10 +540,11 @@ injectGesture(gesturePath: GesturePath): Promise\<void>;
```ts ```ts
import GesturePath from "@ohos.accessibility.GesturePath"; import GesturePath from "@ohos.accessibility.GesturePath";
let gesturePath = new GesturePath(100); import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
try { try {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let gesturePoint = new GesturePoint(100, i * 200); let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
gesturePath.points.push(gesturePoint); gesturePath.points.push(gesturePoint);
} }
axContext.injectGesture(gesturePath).then(() => { axContext.injectGesture(gesturePath).then(() => {
...@@ -578,10 +583,11 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void ...@@ -578,10 +583,11 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
```ts ```ts
import GesturePath from "@ohos.accessibility.GesturePath"; import GesturePath from "@ohos.accessibility.GesturePath";
let gesturePath = new GesturePath(100); import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
try { try {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
let gesturePoint = new GesturePoint(100, i * 200); let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
gesturePath.points.push(gesturePoint); gesturePath.points.push(gesturePoint);
} }
axContext.injectGesture(gesturePath, (err, data) => { axContext.injectGesture(gesturePath, (err, data) => {
...@@ -687,6 +693,8 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi ...@@ -687,6 +693,8 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
```ts ```ts
let attributeName = 'name'; let attributeName = 'name';
let attributeValue;
let rootElement;
try { try {
rootElement.attributeValue(attributeName).then((data) => { rootElement.attributeValue(attributeName).then((data) => {
console.log('get attribute value by name success'); console.log('get attribute value by name success');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册