HarmonyOS object怎么转成Record?

如题:HarmonyOS object怎么转成Record?

阅读 464
1 个回答

参考示例:

interface testObject {
  bundleName: string
  action: string
  entities: number
}

@Entry
@Component
struct Index {
  @State testObj:testObject={
    bundleName: 'hhh',
    action: 'eee',
    entities: 10
  }

  @State testRecord:Record<string,string|number>={}

  aboutToAppear(): void {
    const arr = Object.keys(this.testObj);
    const arr1:string[]|number[] = Object.values(this.testObj);
    for (let i = 0; i < arr.length; i++) {
    this.testRecord[arr[i]]=arr1[i]
  }
  console.log(JSON.stringify(this.testRecord) );
  }

  build() {
    Column(){
    }
  }
}
logo
HarmonyOS
子站问答
访问
宣传栏