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

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

会产生一个丑陋的错误。

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

似乎不会产生错误。

我真的需要 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

哈!我要成功了!

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

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

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

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

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

并获取主题信息!

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

除非我以某种方式偶然发现了其他已弃用的东西,否则似乎你已经完成了。非常感谢。 :beer: :beers: :clinking_glasses: :moneybag:

3 个赞