Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 处理Firebase范围查询响应_Typescript_Firebase_Firebase Realtime Database - Fatal编程技术网

Typescript 处理Firebase范围查询响应

Typescript 处理Firebase范围查询响应,typescript,firebase,firebase-realtime-database,Typescript,Firebase,Firebase Realtime Database,您好,我正在尝试处理中给出的firebase rest服务的响应,下面是我收到的一个示例响应: { "2": { "name": "John", "surname": "Cena" }, "12": { "name": "Murphy", "surname": "R ichard" }, . . . "8": { "name": "Alisha", "surname": "Johnson" } } 因此,响应是

您好,我正在尝试处理中给出的firebase rest服务的响应,下面是我收到的一个示例响应:

{
  "2": {
    "name": "John",
    "surname": "Cena"
  },
  "12": {
    "name": "Murphy",
    "surname": "R ichard"
  },
  .
  .
  .
  "8": {
    "name": "Alisha",
    "surname": "Johnson"
  }
}
因此,响应是一个随机键和员工界面:

interface Employee{
  private name:string;
  private surname:string;
}

响应中的元素数量将有所不同。我想用typescript处理这个问题。我把它作为对象接收回来,它甚至不是地图数组
我想获得一系列员工
。请告知处理方法。

我想说,这一切都取决于您将如何处理数据

// you can assign the response to employees
const employees: any = res;

// or you can convert this to array;
const data = Object.keys(res).map((key) => {
  return { ...res[key], id: key }; <-- here this can be pass to a constructor to return a Employee Object, also you can add a key/id field to the entity.
});

// or many more methods, its all based on how you are going access the data.
//您可以将响应分配给员工
const employees:any=res;
//或者您可以将其转换为数组;
常量数据=Object.keys(res).map((key)=>{
返回{…res[key],id:key};