我使用的是 @pfaffman 的 Feverbee 模板作为自定义的基础,但在论坛中搜索许久后,仍无法解决遇到的问题。以下示例部分显示了来自特定类别的最新 3 条帖子:
然而,我似乎无法将用户头像更改为原始发帖人的头像,而不是最新回复者的头像。我认为类别的 JSON 数据中并未传递该信息,而我在尝试添加它时束手无策。
我需要做出这一更改,因为最新发帖人可能是我们的支持团队成员,而不是需要帮助的人。
好的,你需要拉取用户数据……你可以将 topicListThree 部分编辑为:
ajax("/latest.json?order=posts&ascending=true").then (function(result){
topicListThree = [];
var usersThree = result.users;
result.topic_list.topics.slice(0,3).forEach(function(topic){
topic.posters.forEach(function(poster){
poster.user = $.grep(usersThree, function(e){ return e.id == poster.user_id; })[0];
});
topicListThree.push(Topic.create(topic));
});
component.set('topicListThree', topicListThree);
});
然后在模板中,你可以将 img src 中的 {{topic.last_poster_username}} 部分替换为 {{topic.posters.[0].user.username}}
太棒了,谢谢 @awesomerobot。我已经完成了三分之二,但还需要你的帮助才能最终完成!