promise.all只返回第一个数据
promise.all return only first data
am使用bluebird promise.all api迭代了许多函数,但我似乎只从第一个函数中得到数据返回
var _ = require('lodash');
var x = require('x-ray')();
var sentiment = require('sentiment');
var Promise = require('bluebird');
以及下方的代码
function joyPolitics() {
return new Promise(function(resolve, reject) {
x('http://www.myjoyonline.com/politics.php', 'ul.opinion-listings li', [{
title: '.head .title a',
desc: '.info',
date: '.head',
img: 'div.image-inner > a img@src',
url: '.head .title a@href',
fullStory: x('.head .title a@href', ['.main-article-section .storypane p'])
}])(function(err, obj) {
if (err) {
reject(err)
} else {
_(obj).forEach(function(story) {
var a = story.fullStory;
story.category = 'politics';
story.mood = sentiment(a.join()).score;
});
resolve(obj);
}
})
})
}
function joyEnt() {
return new Promise(function(resolve, reject) {
x('http://www.myjoyonline.com/entertainment.php', 'ul.opinion-listings li'
...
}
function execute() {
return Promise.all(joyEnt(),joyPolitics());
}
当调用上的数据执行时
activateCtrl.execute()
.then(function(data,data1) {
// return activateCtrl.loadToParse(data);
res.json([data,data1]);
}).catch(function(err) {
res.send(err);
})
它返回数据,但data1为空
… Promise.all(joyEnt(),joyPolitics()); …
Promise.all
采用一个数组,而不是多个参数:
Promise.all([joyEnt(),joyPolitics()]);
此外,它的结果承诺不会用多个值来实现,而是用单个数组来实现,因此您需要将then
回调调整为该值,或者使用spread
。您可能还需要考虑使用Promise.join
。
相关文章:
- 使用数据上的角度更改设置集合的第一个元素的动画
- promise.all只返回第一个数据
- 如何从php中第一个动态生成的第二个下拉列表将数据存储到数据库中
- KendoUI AreaChart的分类轴仅基于第一个数据组
- 使用数据表,我想只搜索第一个字母
- 更改第二个组合框的数据,更改第一个组合框的数据
- 在 ajax 将数据传递给 php 后,页面将不会加载第一个条目,但仍会加载其余条目
- For 循环不迭代,输出的数据不超过第一个任务
- 在分页中显示数据表的第一个和最后一个按钮
- 数据表:禁用第一个下一个上一个最后一个,并在处理时显示/搜索记录
- 加载另一个相同页面时,使用新数据激活第一个网页
- JSON 数据未绑定到从 SAPUI5 应用中的第一个视图导航的视图中
- 从 jquery/javascript 中字符串的第一个字符过滤表数据
- PHP 不会在 JavaScript HTTP 请求的第一个页面加载时加载数据
- 数据标签格式化程序在 Highchart 中用于第一个类别
- 当第二个输入框填充第一个框中的数据时显示警报
- 引导工具提示不't在与第一个数据表不同的页面中工作
- 访问Firebase快照中的第一个数据
- 当有更多具有相同名称的数据对象时,如何从JSON响应中仅获取第一个数据对象的值
- js查找从webapi控制器返回的第一个数据属性的模型