访问对象数组中对象的某些数据

时间:2017-10-23 11:03:19

标签: javascript

一直在寻找没有找到解决方案..可能是一个非常愚蠢的问题(可能),但还没有找到一种方法来访问它。

我有Iphone课程:

export class Iphone{
    version: string;
    fixes = [
        {fixlcdprice:null},
        {fixspeakerprice:null}
    ];
}

然后我有一个带数据的Iphone数组

export const IPHONES:Iphone[]=[
{
    version:'Iphone 4',
        fixes:[
           {fixlcdprice:19},
           {fixspeakerprice:19}
       ]

},

   {


    version:'Iphone 4s',
        fixes: [
            {fixlcdprice:19},
            {fixspeakerprice:29}
        ]
}
]

尝试访问修复程序的价格,但我不能。

尝试了

Iphone.fixes[0]  <-- returns (object, object)

然后尝试

Iphone.fixes[0[0]] <-- returns nothing..
Iphone.fixes.fixlcdprice <-- doesnt work

2 个答案:

答案 0 :(得分:3)

看起来像你想要的

Iphone.fixes[0].fixlcdprice

答案 1 :(得分:0)

Iphone=[
{
    version:'Iphone 4',
        fixes:[
           {fixlcdprice:19},
           {fixspeakerprice:19}
       ]

},

   {


    version:'Iphone 4s',
        fixes: [
            {fixlcdprice:19},
            {fixspeakerprice:29}
        ]
}
]

Iphone [0] .fixes [0]为您提供了令人反感的结果

相关问题