Angular2获取具有特定键的记录:值

时间:2017-04-24 11:25:55

标签: typescript

使用特定键:值对从阵列获取所有记录的最简单方法是什么? 数组的模式是这样的:

let arr = '[{"Date":"April 2017 - April 2017","Source":"Foo","Type":"Bar","Value":14},
          {"Date":"April 2017 - April 2017","Source":"Foo","Type":"Bar","Value":14}]';

let source = JSON.parse(arr);

let x = source.map(x=> x.Date);
let y = source.map(x=> x.Value);

console.log(x);
//[ 'April 2017 - April 2017', 'April 2017 - April 2017' ]

console.log(y);
//[ 14, 14 ]

如何获取Priority = 5的所有记录?

1 个答案:

答案 0 :(得分:0)

尝试这种方法

<p *ngFor="let key of keysGetter(items)">{{key + ' : ' + items[key]}}</p>

keysGetter = Object.keys;

Working Example