获取主题的类别ID - 弃用通知:controller:navigation/category 不再存在

我们目前有

  <script type="text/discourse-plugin" version="1.4.0">

  const controller = container.lookup('controller:topic');
  const controllerNavCategory = container.lookup('controller:navigation/category');
  
  const currCategory = controller?.get('model.category_id') || controllerNavCategory?.get("category.id");
  
  console.log('currCategory ', currCategory )
</script>

这运行良好,但现在我看到一个警告:

弃用通知:controller:navigation/category 不再存在,此 shim 最终将被移除。要获取有关当前发现路由的信息,请改用 discovery 服务。[deprecation id: discourse.navigation-category-controller]

如何更新此代码以使用新的 discovery 服务?谢谢。

1 个赞

这应该可以工作:

const service = api.container.lookup('service:discovery');
const currCategory = service.get("category");
6 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.