我正在尝试使用Lodash来返回对象数组的键值。通常这可以返回值,但只返回
[undefined, undefined, undefined, undefined]
对象数组是从API动态创建的,但我没有想到它没有什么特别之处。它具有通常的结构:
[object, object, object]
用
object = {
key: value
key: value
}
我在Angular 2中这样做。
import { Component, OnInit, NgZone, ViewChild } from '@angular/core';
import { RouterModule, Router } from "@angular/router";
import { NewsApiService } from '../service/news-api.service';
import { Http, Response } from '@angular/http';
import { MapComponent } from '../map/map.component';
import * as _ from "lodash";
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit {
private bbcJSON: any;
private alJazeeraJSON: any;
private bingWorldJSON: any;
private bingPoliticsJSON: any;
share(event) {
console.log(_.map(this.bbcJSON, 'title'));
console.log(event);
}
bbcJSON:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
0
:
Object
author
:
"BBC News"
description
:
"The concern comes as the US takes a tough line on North Korea, which may test another nuclear device."
publishedAt
:
"2017-04-14T14:35:21Z"
title
:
"China fears North Korea-US conflict 'at any moment'"
url
:
"http://www.bbc.co.uk/news/world-asia-39600426"
urlToImage
:
"https://ichef.bbci.co.uk/news/1024/cpsprodpb/A4F0/production/_95642224_mediaitem95642223.jpg"
__proto__
:
Object
1
:
Object
2
:
Object
3
:
Object
4
:
Object
5
:
Object
6
:
Object
7
:
Object
8
:
Object
9
:
Object
length
:
10
__proto__
:
Array(0)