You are viewing a single comment's thread from:RE: SteemJS开发的难与易View the full contextView the direct parentlemooljiang (75)in #cn • 6 years ago 村长,在重复取值时第一篇是重复的啊,怎么破
可以加一个逻辑,比如如果startPermlink是post的permlink,就忽略。
function getPosts(author, startPermlink = null, limit = 100, posts = []) { return new Promise((resolve, reject) => { let beforeDate = new Date().toISOString().split('.')[0]; steem.api.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, function (err, result) { if (result.length > 1) { let newResult = []; result.forEach(post =>{ if(post.permlink!=startPermlink){ newResult.push(post); } }); posts = [...posts, ...newResult]; getPosts(author, result[result.length - 1].permlink, limit, posts) .then(resolve) .catch(reject); } else { resolve(posts); } }); }); }
完美!村长牛啊!