js-apis-formextensioncontext.md 2.6 KB
Newer Older
W
wusongqing 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# FormExtensionContext

> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> 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**.

## updateForm

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

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

- Parameters

  | 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.|

- Example

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

## updateForm

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

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

- Parameters

  | 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.|

- Return value

  | Type| Description|
  | -------------- | --------------------------------- |
  | Promise\<void> | Promise returned with the result indicating whether the method is successfully called.|

- 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);});
  ```