modifyClass 失败并带有警告

您好!
我想使用插件 API 修改控制器,但失败了,并出现警告:

[THEME xxx] “controller:full-page-search” 已在容器中缓存。更改将不会生效。

我的代码:

function modifySearchTypes(api) {
    api.modifyClass("controller:full-page-search", {
        pluginId: "modify-search-types",
        init() {
            this._super(...arguments);


            this.set("searchTypes", [
              { name: I18n.t("search.type.default"), id: SEARCH_TYPE_DEFAULT },
              {
                name: this.siteSettings.tagging_enabled
                  ? I18n.t("search.type.categories_and_tags")
                  : I18n.t("search.type.categories"),
                id: SEARCH_TYPE_CATS_TAGS,
              },
            ]);
            this.selected = [];
        },
    });
}

export default {
    name: "modify-search-types",
    initialize() {     
        withPluginApi("0.10.0", modifySearchTypes);
    },
};

我该如何处理?
非常感谢!

请参阅 api.modifyClass sometimes(!) not working - #12 by RGJ

2 个赞

谢谢!
但是,下面的代码仍然失败并显示此警告。

function modifySearchTypes(api) {
    api.modifyClass("controller:full-page-search", {
        pluginId: "modify-search-types",
        init() {
            this._super(...arguments);


            this.set("searchTypes", [
              { name: I18n.t("search.type.default"), id: SEARCH_TYPE_DEFAULT },
              {
                name: this.siteSettings.tagging_enabled
                  ? I18n.t("search.type.categories_and_tags")
                  : I18n.t("search.type.categories"),
                id: SEARCH_TYPE_CATS_TAGS,
              },
            ]);
            this.selected = [];
        },
    });
   const searchController = api.container.lookup("controller:full-page-search");
}

export default {
    name: "modify-search-types",
    initialize() {     
        withPluginApi("0.10.0", modifySearchTypes);
    },
};

在这种情况下,我不知道。

1 个赞

我在我的主题组件中覆盖了全页搜索的模板。这有什么影响吗?