const ajax = require('discourse/lib/ajax').ajax;
const Topic = require('discourse/models/topic').default;
setupComponent(args, component) {
ajax("/tag/featured.json").then(function (result) {
let featuredTopics = [];
// Create an empty array, we'll push topics into it
var featuredUsers = result.users;
// Get the relevant users
result.topic_list.topics.slice(0, 4).forEach(function (topic) {
// We're extracting the topics starting at 0 and ending at 4
// This means we'll show 3 total. Increase 4 to see more.
topic.posters.forEach(function (poster) {
poster.user = $.grep(featuredUsers, function (e) { return e.id == poster.user_id; })[0];
});
// Associate users with our topic
featuredTopics.push(Topic.create(topic));
// Push our topics into the featuredTopics array
});
}) //end result.topic.topic_list...
component.set('featuredTopics', featuredTopics); //this is where the topics get added to the component
component.set("loadingTopics", false); //my above code doesn't have a loader. but this is there if you do want a loader. Have to add to hbs file for that in addition. See linked post on meta above
}); //end ajax
}//end setup component
적어도 제 경우, 이 방법으로 새 템플릿의 플러그인 아웃렛에 “featured” 태그가 있는 주제를 로드하는 데 성공했습니다.