# 获取常规主题的摘要

**URL:** <https://meta.discourse.org/t/get-excerpt-for-regular-topics/33482>\
**Category:** Support\
**Created:** [2015年九月19日 22:05 UTC](https://meta.discourse.org/t/get-excerpt-for-regular-topics/33482 "2015-09-19T22:05:39Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)\
**Post date:** [2020年四月14日 13:58 UTC](https://meta.discourse.org/t/get-excerpt-for-regular-topics/33482/10 "2020-04-14T13:58:47Z")

</div>

你好，我也遇到过同样的问题，通过重新获取主题来获取所需数据解决了。我在 `topic-list-item.js` 组件中使用了 `Ember.PromiseProxyMixin` 来实现。如何使用它，请阅读这里：[Use Ember.PromiseProxyMixin in a theme](https://meta.discourse.org/t/using-ember-promiseproxymixin-in-discourse-development/147231)

代码大致如下：

```js
// 我使用了自定义的 memoize 函数来减少请求次数
const getTopic = memoize(id => ajax(`/t/${id}.json`).then(data => data));
// ...
// 在组件内部

  @discourseComputed("topic")
  topicPromise(topic) {
    return getTopic(topic.id);
  },

  @discourseComputed("topicPromise")
  topicProxy() {
    const promise = this.get("topicPromise");
    return promise && PromiseObject.create({ promise });
  },

  postStream: reads("topicProxy.content.post_stream"),

  @discourseComputed("postStream")
  excerpt(postStream) {
    if (!this.get("postStream")) return false;
    return `${stripHtml(postStream.posts[0].cooked).slice(0, 150)}...`;
  },

```

`stripHtml` 是一个自定义函数，用于移除首帖中的 HTML。

在 `topic-list-item.hbs` 中，你可以这样写：

```handlebars
  {{#if topicProxy.isFulfilled}}
    <div class="excerpt">
      {{#if excerpt}}
        {{html-safe excerpt}}
      {{/if}} 
    </div>
  {{/if}}

```

---

_[View the full topic](https://meta.discourse.org/t/get-excerpt-for-regular-topics/33482)._
