js-apis-application-formBindingData.md 2.4 KB
Newer Older
1
# @ohos.application.formBindingData (formBindingData)
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

The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information.

> **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.
> This module is deprecated since API version 9. You are advised to use [FormBindingData](js-apis-app-form-formBindingData.md) instead.
## Modules to Import

```ts
import formBindingData from '@ohos.application.formBindingData';
```

## FormBindingData

Describes a **FormBindingData** object.

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

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| data | Object | Yes| Data to be displayed on the JS widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|


## createFormBindingData

createFormBindingData(obj?: Object | string): FormBindingData

Creates a **FormBindingData** object.

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

**Parameters**

| Name| Type          | Mandatory| Description                                                        |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
38
| obj    | Object\|string | No  | Data to be displayed on the JS widget. The value can be an object containing multiple key-value pairs or a string in JSON format. The image data is identified by **'formImages'**, and the content is multiple key-value pairs, each of which consists of an image identifier and image file descriptor. The final format is {'formImages': {'key1': fd1, 'key2': fd2}}.|
39 40 41 42 43 44 45 46 47 48 49 50


**Return value**

| Type                               | Description                                   |
| ----------------------------------- | --------------------------------------- |
| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.|


**Example**

```ts
G
Gloria 已提交
51
import formBindingData from '@ohos.application.formBindingData';
52 53 54
import fs from '@ohos.file.fs';

try {
55
  let fd = fs.openSync('/path/to/form.png');
56
  let obj = {
57 58
    'temperature': '21°',
    'formImages': { 'image': fd }
59
  };
60
  formBindingData.createFormBindingData(obj);
61
} catch (error) {
G
Gloria 已提交
62
  console.error('catch error, error: ${JSON.stringify(error)}');
63
}
64
```