Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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
Angular 当对象键未知时,如何获取数组对象的对象?_Angular_Typescript - Fatal编程技术网

Angular 当对象键未知时,如何获取数组对象的对象?

Angular 当对象键未知时,如何获取数组对象的对象?,angular,typescript,Angular,Typescript,我有一个对象数组,其中每个对象都有一个对象,如下所示 [{ "-KzbaPS3vuZTG2LbuB3j": { "age": "24", "branchname": "columbia", "city": "hyd", "date": 1511418820987, "gender": "M", "id": "rcjcx8", "mobile": "9898989898",

我有一个对象数组,其中每个对象都有一个对象,如下所示

[{
    "-KzbaPS3vuZTG2LbuB3j": {
        "age": "24",
        "branchname": "columbia",
        "city": "hyd",
        "date": 1511418820987,
        "gender": "M",
        "id": "rcjcx8",
        "mobile": "9898989898",
        "name": "Patient1",
        "op": 100
    }
}, {
    "-KzTh7RTtTWviL4HkHv0": {
        "age": "21",
        "branchname": "kims",
        "city": "vizag",
        "date": 1511334303070,
        "gender": "F",
        "id": "45krxb",
        "mobile": "9898989898",
        "name": "aruna",
        "op": 100
    },
    "-KzTiCIheMPJIpJhPXQJ": {
        "age": "22",
        "branchname": "kims",
        "city": "hyderabad",
        "date": 1511420593865,
        "gender": "F",
        "id": "c7iqws",
        "mobile": "9878787878",
        "name": "vineesha",
        "op": 100
    },
    "-KzTnzLnRsdFWg-m5b9U": {
        "age": "26",
        "branchname": "kims",
        "city": "bheemavaram",
        "date": 1511420593865,
        "gender": "F",
        "id": "ujtgz",
        "mobile": "9876787898",
        "name": "Madhavi",
        "op": 100
    }
}]

对象未知,那么如何将对象的所有对象合并到一个数组中?

如果您对Lodash没有意见,可以执行以下操作:

// assuming the above data is in variable "data"

let structuredData = _.flatten(data).reduce((a,c) => _.assign(c), {});
你可以用

array.forEach(obj=>{
设key=Object.keys(obj)[0];
让yourValue=obj[key];
//您的值={“年龄”:“21”,“id”:“rcjcx8”…}在您的案例中,用于第一项
});

迭代并获取键,然后使用键获取值

HTML文件

{{jsonDataKeys}}

<hello name="{{ name }}"></hello>
<p>
  Start editing to see some magic happen :)
</p>
<!--<div>{{jsonData | json}}</div>-->

 <div *ngFor="let arr of jsonData">
  <div *ngFor="let item of jsonDataKeys">
    item : {{item}}
    {{arr[item] | json}}
    <br>
    <br>
  </div>
 </div>
{{jsonDataKeys}

开始编辑以查看发生的奇迹:)

项目:{{item} {{arr[项目]| json}

{{jsonDataKeys}}

<hello name="{{ name }}"></hello>
<p>
  Start editing to see some magic happen :)
</p>
<!--<div>{{jsonData | json}}</div>-->

 <div *ngFor="let arr of jsonData">
  <div *ngFor="let item of jsonDataKeys">
    item : {{item}}
    {{arr[item] | json}}
    <br>
    <br>
  </div>
 </div>