你好各位,
我正在努力获取过去 30 天内回复最多的前 3 个主题,我只想显示这些主题,并且我正在自定义 showcase category 插件,所以在 JS 端我运行了下面的代码,但它似乎返回了一个 Promise。任何人都可以告诉我如何做到这一点吗?
showcased-topic-list.js
this.store.findFiltered("topicList", filter).then((topicList) => {
var idaas = [];
var final_arr = [];
topicList.topics = topicList.topics.forEach(async (t) => {
const response = await ajax(`/t/${t.id}/posts.json`).then(async (result) => {
await result.post_stream.posts.forEach((p) => {
let date1 = new Date();
let date2 = new Date(p.created_at);
let Difference_In_Time = date1.getTime() - date2.getTime();
let Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);
if (Difference_In_Days <= 30) {
idaas.push(result.id);
}
});
return idaas;
});
final_arr.push(response);
});
});
example:
var smallarrq = ['71782', '72307'];
this.set(
"topicList",
topicList.topics.filter((t) => smallarrq.includes(t.id)).slice(0, settings.max_list_length)
);
我希望这个 final_arr 数组看起来像上面的 smallarrq 数组,但它返回的是 Promise。
请帮忙各位,我已经做了很多天了。
谢谢,