为整页搜索结果项添加类?

我正试图为 full-page-search 返回结果中的帖子的类别添加一个类。我尝试过将 modifyClass 应用于 controller/full-page-searchcomponent/search-result-entry,包括使用 modifyClass 错误解决方法 中的方法,但我甚至无法让 console.logalert 工作。是否有其他方法可以为 fps-result 帖子项添加类?我基本上是在寻找 decorateCookedElement 的 full page search 等效项。

api.modifyClass('controller:full-page-search', {
   pluginId: 'mute-categories-search',
   actions: {
    newActionHere() {
        console.log("test")
    }
   }
});
const controller = api.container.lookup('controller:full-page-search');
1 个赞

我通过使用 decoratePluginOutlet 然后遍历层级结构来查找徽章中的类别链接并将其添加到主题 div 中,最终获得了类别 ID。有没有更好的方法来做到这一点?

api.decoratePluginOutlet(
   "full-page-search-category",
   (elem, args) => {
    let searchCategory = elem.parentElement.parentElement
    let fpsTopic = searchCategory.parentElement.parentElement
    let category_id = searchCategory.children[0].getAttribute('href').split("/").slice(-1);
    console.log(category_id)
    fpsTopic.classList.add("category_" + category_id)
   }
 );
1 个赞
2 个赞

此主题已在 3 天后自动关闭。不再允许回复。