# הצג רשימת נושאים על פי מערך של מזהי נושאים

**URL:** https://meta.discourse.org/t/display-list-of-topics-by-array-of-topics-ids/86778
**Category:** Development
**Created:** [4 במאי,‏ 2018,‏ 6:41pm UTC](https://meta.discourse.org/t/display-list-of-topics-by-array-of-topics-ids/86778 "2018-05-04T18:41:36Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)
#### Post date: [15 בפברואר,‏ 2020,‏ 12:03am UTC](https://meta.discourse.org/t/display-list-of-topics-by-array-of-topics-ids/86778/2 "2020-02-15T00:03:14Z")

</div>

I also need this functionality. right now I am doing it like this, but this takes way too long.

```javascript
    const selectedTopics = this.selectedTopics
     //eat topics as ids and let out real topics
     this.selectedTopicsID.forEach(function(tid,index){
       Topic.find(tid,{}).then(results => {
         selectedTopics.pushObject(results)
       })
     });

```

I am about to reopen the listcontroller in my plugin.rb and add a new endpoint and reopen the topic-list in the frontend initializer and do something similar to this:

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/topic-list.js.es6#L129](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/topic-list.js.es6#L129)  
But there must be an easier way to do this. Is there really no endpoint yet to fetch topics in bulk by id?  
I would be very glad for some help 😃  
EDIT: This is how I solved this problem for me:  
[https://github.com/spirobel/projects/commit/b514a366f05005888805fc2f57118dfd9fd61fa1](https://github.com/spirobel/projects/commit/b514a366f05005888805fc2f57118dfd9fd61fa1)  
This is how it can be used.

```javascript
import TopicList from 'discourse/models/topic-list';
    const selectedTopics = this.selectedTopics
    //eat topics as ids
    TopicList.topics_array(this.selectedTopicsID).then(results => selectedTopics.pushObjects(results.topic_list.topics))

```

right now this still has the downside, that it doesnt return “real” Topic objects, but I guess adding a line like this will fix it:

> <https://github.com/discourse/discourse/blob/25fd2b544a6cc68b8cf6cd5a16178e52214c01e9/app/assets/javascripts/discourse/models/user.js.es6#L732>

I am still unsure if this is the right way to do it and/or if this breaks security.  
Another thing that could be done: first look in the store if the record is already there and then only load what isnt there, with fromMap. Similar to:

> <https://github.com/discourse/discourse/blob/cd5b7109d04722df5c39b2ded9fa4ead6c290ce4/app/assets/javascripts/discourse/models/store.js.es6#L355>

anyways this is getting to verbose here 😃  
This is my final solution I will call it a day now:  
[https://github.com/spirobel/projects/commit/004da260f15486bf71ca48fa7c6ecee11ce646f0](https://github.com/spirobel/projects/commit/004da260f15486bf71ca48fa7c6ecee11ce646f0)

---

_[View the full topic](https://meta.discourse.org/t/display-list-of-topics-by-array-of-topics-ids/86778)._
