1# @ohos.application.formBindingData (卡片数据绑定类) 2 3<!--Kit: Form Kit--> 4<!--Subsystem: Ability--> 5<!--Owner: @cx983299475--> 6<!--Designer: @xueyulong--> 7<!--Tester: @chenmingze--> 8<!--Adviser: @Brilliantry_Rui--> 9卡片数据绑定模块提供卡片数据绑定的能力。包括FormBindingData对象的创建、相关信息的描述。 10 11> **说明:** 12> 13> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 从API version 9开始不再维护,建议使用[formBindingData](js-apis-app-form-formBindingData.md)替代。 15## 导入模块 16 17```ts 18import formBindingData from '@ohos.application.formBindingData'; 19``` 20 21## FormBindingData 22 23FormBindingData相关描述。 24 25**系统能力:** SystemCapability.Ability.Form 26 27| 名称 | 类型 | 必填 | 说明 | 28| -------- | -------- | -------- | -------- | 29| data | Object | 是 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。| 30 31 32## formBindingData.createFormBindingData 33 34createFormBindingData(obj?: Object | string): FormBindingData 35 36创建一个FormBindingData对象。 37 38**系统能力:** SystemCapability.Ability.Form 39 40**参数:** 41 42| 参数名 | 类型 | 必填 | 说明 | 43| ------ | -------------- | ---- | ------------------------------------------------------------ | 44| obj | Object\|string | 否 | JS卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以'formImages'作为标识,内容为图片标识与图片文件描述符的键值对{'formImages': {'key1': fd1, 'key2': fd2}}。 | 45 46 47**返回值:** 48 49| 类型 | 说明 | 50| ----------------------------------- | --------------------------------------- | 51| [FormBindingData](#formbindingdata) | 根据传入数据创建的FormBindingData对象。 | 52 53 54**示例:** 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