我做的nativescript /角度的教程,我發現代碼中的東西,我不明白並希望澄清一下。什麼是「結果」是指從nativescript的http.get請求獲得一個可觀察的.MAP運營商/角
在第4章(Nativescript模塊),當他們做了http.get resquest檢索購物清單,他們得到的可觀察我發現它是throught一些地圖操作過去了,這裏是代碼:
import { Injectable } from "@angular/core";
import { Http, Headers } from "@angular/http";
import { Observable } from "rxjs/Rx";
import "rxjs/add/operator/map";
import { Config } from "../config";
import { Grocery } from "./grocery";
@Injectable()
export class GroceryListService {
constructor(private http: Http) {}
load() {
let headers = new Headers();
headers.append("Authorization", "Bearer " + Config.token);
return this.http.get(Config.apiUrl + "Groceries", {
headers: headers
})
.map(res => res.json())
.map(data => {
let groceryList = [];
data.Result.forEach((grocery) => { //<------HERE
groceryList.push(new Grocery(grocery.Id, grocery.Name));
});
return groceryList;
})
.catch(this.handleErrors);
}
handleErrors(error: Response) {
console.log(JSON.stringify(error.json()));
return Observable.throw(error);
}
}
我的問題是,什麼是「結果」是指在第二.MAP
他們爲什麼不乾脆把
data.forEach((grocery) => {
我問,因爲我不知道,如果它是從.map(res => res.json)或其他東西得到的可觀察對象的對象屬性。
你能指出我的在哪裏呢,有些文檔「結果」從何而來又意味着什麼?
感謝advaced。
返回的數據謝謝了很多,這非常有意義。 –