1# @ohos.application.formBindingData (formBindingData) 2 3<!--Kit: Form Kit--> 4<!--Subsystem: Ability--> 5<!--Owner: @cx983299475--> 6<!--Designer: @xueyulong--> 7<!--Tester: @chenmingze--> 8<!--Adviser: @Brilliantry_Rui--> 9The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information. 10 11> **NOTE** 12> 13> 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. 14> This module is deprecated since API version 9. You are advised to use [formBindingData](js-apis-app-form-formBindingData.md) instead. 15## Modules to Import 16 17```ts 18import formBindingData from '@ohos.application.formBindingData'; 19``` 20 21## FormBindingData 22 23Describes a **FormBindingData** object. 24 25**System capability**: SystemCapability.Ability.Form 26 27| Name| Type| Mandatory| Description| 28| -------- | -------- | -------- | -------- | 29| 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.| 30 31 32## formBindingData.createFormBindingData 33 34createFormBindingData(obj?: Object | string): FormBindingData 35 36Creates a **FormBindingData** object. 37 38**System capability**: SystemCapability.Ability.Form 39 40**Parameters** 41 42| Name| Type | Mandatory| Description | 43| ------ | -------------- | ---- | ------------------------------------------------------------ | 44| 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}}.| 45 46 47**Return value** 48 49| Type | Description | 50| ----------------------------------- | --------------------------------------- | 51| [FormBindingData](#formbindingdata) | **FormBindingData** object created based on the passed data.| 52 53 54**Example** 55 56```ts 57import { formBindingData } from '@kit.FormKit'; 58import { fileIo } from '@kit.CoreFileKit'; 59import { common } from '@kit.AbilityKit'; 60@Entry 61@Component 62struct Index { 63 content = this.getUIContext().getHostContext() as common.UIAbilityContext; 64 pathDir: string = this.content.filesDir; 65 createFormBindingData() { 66 try { 67 let filePath = this.pathDir + "/form.png"; 68 let file = fileIo.openSync(filePath); 69 let formImagesParam: Record<string, number> = { 70 'image': file.fd 71 }; 72 let createFormBindingDataParam: Record<string, string | Record<string, number>> = { 73 'name': '21°', 74 'imgSrc': 'image', 75 'formImages': formImagesParam 76 }; 77 formBindingData.createFormBindingData(createFormBindingDataParam); 78 } catch (error) { 79 console.error(`catch error, error: ${JSON.stringify(error)}`); 80 } 81 } 82 build() { 83 Button('createFormBindingData') 84 .onClick((event: ClickEvent)=>{ 85 this.createFormBindingData(); 86 }) 87 } 88} 89``` 90