# 获取 Glimmer 组件访问父级的内容

**URL:** <https://meta.discourse.org/t/get-glimmer-component-access-to-stuff-from-the-parent/316898>\
**Category:** Development\
**Created:** [2024年七月17日 20:18 UTC](https://meta.discourse.org/t/get-glimmer-component-access-to-stuff-from-the-parent/316898 "2024-07-17T20:18:02Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2024年七月18日 16:56 UTC](https://meta.discourse.org/t/get-glimmer-component-access-to-stuff-from-the-parent/316898/9 "2024-07-18T16:56:11Z")

</div>

> [@david](#):
>
> 好的，这应该通过[此提交](https://github.com/discourse/discourse/commit/445951e854cbe86463d2e9f1054a902b0fee3c88)得到修复。你能确认现在看到警告了吗？

```plaintext
{{log "rating this parent" this.parentView._parentView.topic}}

```

会产生一个丑陋的错误。

```plaintext
<RatingOne @scaleValue={{this.scaleValue}} @passedRouter={{this.router}} @topic={{this.parentView}} />

```

似乎不会产生错误。

> [@david](#):
>
> 你上面提到了“before-topic-list-body”。它有所有这些参数：
> 
> [discourse/app/assets/javascripts/discourse/app/components/topic-list.hbs at 94d4b187ef9543d3a4c19ad3ce4f4f213be89d19 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/94d4b187ef9543d3a4c19ad3ce4f4f213be89d19/app/assets/javascripts/discourse/app/components/topic-list.hbs#L27C9-L37C3)

我真的需要 `above-topic-list-item`，但感谢你精彩的例子，我发现它应该在 `outletArgs` 中包含主题，

[https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/topic-list/topic-list-item.gjs#L284](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/topic-list/topic-list-item.gjs#L284)

哈！我要成功了！

所以 `outletArgs` 意味着它现在在那个东西的 `this` 中了吗？（看起来是这样——我以为我需要以某种方式在 `args` 中查找……）

所以，在我的连接器 hbs 中，我可以访问 `this.topic`，然后像这样调用我的组件：

```plaintext
<RatingOne @name="one" @topic={{this.topic}} />

```

然后在 `RatingOne` 组件的 hbs 中（有一天会重命名为 `rating`，因为我已经弄清楚如何传递东西给它了），我可以

```plaintext
  这是主题 {{this.topic.id}} {{this.topic.title}}
  这是分类 ID： {{this.topic.category_id}})

```

并获取主题信息！

现在我看到主题了，现在我可以去添加我的参数到主题序列化器，对吗？（也许最好只传递给分类……或者也许我只会传递一个“doTheThing”值到序列化器，并从 `SiteSettings` 获取实际的东西，因为我认为他们想要这个在站点而不是分类级别）。

除非我以某种方式偶然发现了其他已弃用的东西，否则似乎你已经完成了。非常感谢。 🍺 🍻 🥂 💰

---

_[View the full topic](https://meta.discourse.org/t/get-glimmer-component-access-to-stuff-from-the-parent/316898)._
