Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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_Ionic Framework - Fatal编程技术网

Angular 将数组表达式转换为对象角度

Angular 将数组表达式转换为对象角度,angular,ionic-framework,Angular,Ionic Framework,我从http请求返回了这个json [ { "player": { "1100": { "name": "Andy", "position": "Keeper" }, "1927": { "name": "Cole", "position": "benchwarmer"

我从http请求返回了这个json

[
  {
        "player": {
            "1100": {
                "name": "Andy",
                "position": "Keeper"
            },
            "1927": {
                "name": "Cole",
                "position": "benchwarmer"
            },
            "2399": {
                "name": "Derrick",
                "position": "Striker"
            },
            "2900": {
                "name": "Cole",
                "position": "normal supporter"
            }
        },
        "substitutions": [
            {
                "playerin": 1100,
                "playerout": 1927,
                "time": 58
            },
            {
                "playerin": 2399,
                "playerout": 2900,
                "time": 58
            }
        ]
    }

]
这是我的ts

Object = Object;

this.http.get('http://example.com/example.php?matchid='+this.matchId)
            .map(res => res.json())
            .subscribe(res => { 
              this.substitutes = res[0].substitutions;
              this.players = res[0].players;


 });
在循环替换的过程中,我希望它能显示玩家的名字,我需要将playerinplayerout数据更改为object,但是没有这样做。这是我的失败代码示例,返回未定义的玩家

//failed 1
<div *ngFor="let subH of substitutes">
    {{players[subH.playerin].name}}
    </div> 
//failed 2
<div *ngFor="let subH of Object.keys(substitutes)"> 
    {{players[subH.playerin].name}}
    </div> 
//失败1
{{玩家[subH.playerin].name}
//失败2
{{玩家[subH.playerin].name}
我怎样才能做到呢

this.substitutes = res.substitutions;
this.players = res.players;
应该是

this.substitutes = res[0].substitutions;
this.players = res[0].player;

res
根据您的json,它似乎是一个数组,而不是一个对象My bad@SurajRao,我对它进行了编辑,因为它是从原始文件复制粘贴编辑来简化它。问题是我不能给玩家打电话[subH.playerin],因为playerin还不是一个对象。这就是我所想的可能是错误的,也可能是@SurajRao的副本。不,这完全不同。你能添加所有相关代码吗?@PardeepJain我的错,我已经编辑了它,因为它是从原始文件复制粘贴编辑来简化它。问题是我不能给玩家打电话[subH.playerin],因为playerin还不是一个对象。这就是我想的可能也是错的是的我做了…而且它在我的网站上不起作用…真正的文件是相当复杂的,虽然它包含数千行。我以前给玩家打过一次电话[一些表达式],它正在工作…但是当我在另一个片段中校准它时,它正在变得不确定…哦,我刚刚发布了答案,通过查看问题中的场景,它在我的示例中工作得很好离子片段在同一个文件中component@PardeepJain玩家id:1100,1192是一个对象,这就是为什么我在调用{{players[subH.playerin]?.name}时没有定义的原因