プロジェクトをAngular2で記述します。ここで、JSONを取得し、すべて配列rooms
を取得します。ここでObjectからデータを取得して配列に格納する方法
は
@Injectable()
export class RoomlistService {
constructor(private http: Http) { }
getRooms(room) {
console.log('get all rooms: ');
return this.http.get('../../assets/rooms/' + room + '.json')
.map(response => response.json());
}
}
私は右JSONファイルを取得するのに役立ち、ここでは、このサービスを使用して、私のコンポーネントであり、そして今それのために、だから、データ
ngOnInit() {
this.routeUrl.paramMap.subscribe((param) => {
this.buildingID = param.get('id');
this.service.getRooms(this.buildingID).subscribe(data => {
console.log(data);
});
});
}
を得る私のサービスであり、正常に動作し、かつconsole.log
で、私はこのobject
私がしたいのは、すべてrName
を取得して配列に格納することです。 しかし、私が試したすべてが私を助けなかった。あなたはそれを解決するために私を助けてくれますか?