【发布时间】:2019-07-18 10:42:02
【问题描述】:
我是 React Native 和一般编码的新手。我在 upwork 上支付了一些代码,并且很难将其集成到我的程序中。
async pullBatch(since){
let param = {
userScreenName: '?screen_name=google',
count: "&count=5",
retweets: "&include_rts=false",
replies: "&exclude_replies=false",
trim: "&trim_user=true",
since: "&max_id=" + since
};
let twitterRest = new TwitterRest(); //create a new instance of TwitterRest Class
let batch = await twitterRest.pullTweets(param); //pull the Google TimeLine
return batch;
}
pullTimeline(){
let timeLine = []
for(i = 0; i <= 2; i++){
let currentBatch = this.pullBatch("1098740934588751900")
console.log(currentBatch);
timeLine = timeLine.concat(currentBatch);
}
console.log(timeLine);
// timeLine = currentBatch
return(timeLine)
}
我相信在运行 pullTimeLine() 时,程序会返回一个包含三个 Promise 的数组。 (我也在 pullBatch() 之前用“await”运行了代码,但是告诉我 await 是一个保留字会出错)这意味着我犯了两个错误:
- 我没有正确理解 JS 中的 promise 或它们是如何解决的。
- 我错误地连接了数组。
我一直在努力学习,所以虽然我非常感谢有关代码修复的建议,但如果您能告诉我我在理解方面的失误在哪里,我也非常感激。
谢谢
【问题讨论】:
标签: javascript reactjs api es6-promise fetch-api