私の返答が返され、未定義として印刷される理由について質問があります。インポートされたクラスを使用してES6で空の約束が返される
これは私のmain.jsの私の方法です。私は未定義の応答を取得していますどこ
find() {
return this.serviceFactory
.createRequest()
.withId(333)
.sendAsGet().then(response => {
console.log(response);
});
}
上記にconsole.log(レスポンス)があります。
これはparseJSONContent方法でthis.serviceFactory
export class ServiceFactory {
constructor(http) {
this.http = http;
this.http.baseUrl = serviceUrlParts.baseUrl;
this.endpoint = "";
this.id = "";
}
createRequest() {
return this;
}
withId(id) {
this.id = id;
return this;
}
setEndPoint(endpoint){
this.endpoint = serviceUrlParts.baseUrl + endpoint;
}
sendAsGet() {
return this.http.get(`${this.endpoint}/${this.id}`)
.then(response => {
this.parseJSONContent(response);
}).catch(error => {
console.log(error);
});
}
parseJSONContent(response) {
console.dir(JSON.parse(response.content));
return JSON.parse(response.content);
}
}
はconsole.dir(JSON.parse(response.content))として使用されるインポートクラスが正しいオブジェクトを印刷されAPIから返されました。どこかに戻ってコールに戻り、失われています。何が起こっているのかについてのいくつかの洞察は非常に高く評価されるでしょう!
.then(response => {
this.parseJSONContent(response);
})
変更それに:ここで
をので、あなた*やる*リターン 'undefined'(または、ドンこれらのコールバックすべてから何も返さない)。 – Bergi