私は大きなアプリケーションの中に小さなノードのjsデータの廃棄機能を構築しています。私はJavascriptの約束とそれほど違和感がないので、私の誤解を許してください。私のタイトルが本当に私の問題の枠組みになっているかどうかは分かりませ約束事としての機能
ので、私はこれがあります。
const getAxiosUrls = function() { axios.get("http://localhost:3000/gatable")
.then(function (response) {
return urls = response.data.rows.map(([x, y, z]) => y)
})}
と、この:
const getNbShares = function() {
Promise.map(urls, requestPromise)
.map((htmlOnePage, index) => {
const $ = cheerio.load(htmlOnePage);
const share = $('.nb-shares').html();
let shareTuple = {};
shareTuple[urls[index]] = share;
return shareTuple;
})
.catch((e) => console.log('We encountered an error' + e));
}
を、私はこれを行うしたいと思います:
getAxiosUrls()
.then(getNbShares)
.then(res.json)
私はいくつかのものを試してみましたが、ほとんどのき次のエラーが発生した時刻: Cannot read property 'then' of undefined
。また、私getAxiosUrls
作品が正しく、私はこの
getAxiosUrls()
setTimeout(function() {console.log(urls)},5000)
をやったし、期待通りにログが私に応答を返すことを確認します。それで私は何を欠場したのですか?
'getAxiosUrls'と' getNbShares'は何も返さない:https://stackoverflow.com/documentation/javascript/231/promises – Andreas
'return'の問題のほかに、あなたは以前の'const getNbShares = function(urls){...'のような結果です。 – Redu