js-apis-formextensioncontext.md 3.0 KB
Newer Older
1 2
# FormExtensionContext

W
wusongqing 已提交
3 4
> **NOTE**
>
5 6 7 8
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Implements the context that provides the capabilities and APIs of **FormExtension**. This class is inherited from **ExtensionContext**.

W
wusongqing 已提交
9 10 11 12 13 14
## Modules to Import

```js
import FormExtension from "@ohos.application.FormExtension";
```

15 16 17 18 19 20 21 22 23 24
## FormExtensionContext.updateForm

updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void

Updates a widget. This method uses a callback to return the result.

**System capability**: SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
25 26 27 28 29
| Name         | Type                                                        | Mandatory| Description                                  |
| --------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| formId          | string                                                       | Yes  | ID of the widget that requests to be updated.                    |
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes  | New data of the widget.                        |
| callback        | AsyncCallback\<void>                                         | Yes  | Callback used to return the result indicating whether the method is successfully called.|
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

**Example**

  ```js
  let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
  this.context.updateForm(formId, obj2, (data)=>{
      console.log('FormExtension context updateForm, data:' + data);
  });
  ```

## FormExtensionContext.updateForm

updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>

Updates a widget. This method uses a promise to return the result.

**System capability**: SystemCapability.Ability.Form

**Parameters**

W
wusongqing 已提交
50 51 52 53
| Name         | Type                                                        | Mandatory| Description              |
| --------------- | ------------------------------------------------------------ | ---- | ------------------ |
| formId          | string                                                       | Yes  | ID of the widget that requests to be updated.|
| formBindingData | [formBindingData.FormBindingData](js-apis-formbindingdata.md#formbindingdata) | Yes  | New data of the widget.    |
54 55 56

**Return value**

W
wusongqing 已提交
57 58 59
| Type          | Description                             |
| -------------- | --------------------------------- |
| Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|
60 61 62 63 64 65 66 67 68 69 70

**Example**

  ```
  let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
  this.context.updateForm(formId, obj2)
      .then((data)=>{
          console.log('FormExtension context updateForm, data:' + data);
      }).catch((error) => {
      console.error('Operation updateForm failed. Cause: ' + error);});
  ```