任何想法爲什麼從getBatchedContent
返回的值爲null
,給定下面的代碼示例?request-promise實現返回null`
import rp from 'request-promise';
import _ from 'lodash';
function getBatchedContent(size, page) {
return Promise.resolve(fetchBatchedContent(size, page)); // Getting `null` here.
}
function fetchBatchedContent(size, page) {
var options = {
uri: `http://www.example.com/posts?type=vogue-fashion-shows&filter[posts_per_page]=${size}&page=${page}`
};
return rp(options)
.then(function (res) {
res = JSON.parse(res);
// res is an array of content objects.
return _.map(res, function (obj) { // logged value of `_.map()` is correct.
return transformContent(obj);
});
});
}
function transformContent(obj) {
return {
id: obj.ID,
title: obj.title,
// etc.
};
}
僅供參考,'getBatchedContent()'不提供其他功能。你可以直接調用'fetchBatchedContent()'並獲得相同的結果。 – jfriend00
如果你正在談論解決的承諾價值爲'null',那麼我會看你的'rp(...)。then()'處理,看它是否真的在做你期望的並且實際返回期望值。 – jfriend00