任何想法为什么从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