0

我们能不能配置一个搜索在选择搜索功能时自动打开,我以为可以通过配置实现,但是找不到哪里可以配置。它已经在https://www.ibm.com/developerworks/community/forums/html/topic?id=fbac6330-f636-4745-924a-a713f4f9a309&ps=50&tags=&query=&filter=&sortBy=&order=asc上讨论过, 但是有没有答案怎么做,只有建议:“你可以用插件编码。” 如何使用插件来完成?

4

1 回答 1

0

我没有在互联网上找到答案。我能够自己编写代码。希望它会帮助别人。

我做了 ContentNavigator Dojo 类 ecm/widget/search/SearchSelector 的猴子补丁

请在下面查看我的代码:

            var searchSelectorPrototype = searchSelector.prototype; 
            var old_createTree = searchSelectorPrototype._createTree; 
            searchSelectorPrototype._createTree = function () {

                old_createTree.apply(this, arguments);

                this._tree.expandAll();// we need to expand tree to be able to get search templates by _tree.getNodesByItem("all")[0].getChildren();
                var that = this;

                var i = 0;
                var myVar = setInterval(myTimer ,100);//need to wait until expandAll() completed
                function myTimer() {
                    i++;
                    var searchTemplates = that._tree.getNodesByItem("all")[0].getChildren();
                    if (i>50){
                        clearInterval(myVar);
                        console.log("not able to get search templates from _tree.getNodesByItem(\"all\")[0].getChildren()");
                    }
                    if (searchTemplates.length > 0 ){
                        clearInterval(myVar);
                        new searchPlugin.config.PluginConfig().getConfiguration(// we need to know which search template to open, I added configuration parameter "autoSearchTemplateName" to plugin
                            function(response) {
                                var templateName;
                                response.configuration.forEach(function (configurationItem) {
                                    if (configurationItem.name == 'autoSearchTemplateName'){
                                        templateName = configurationItem.value;
                                    }
                                });
                                array.forEach(searchTemplates, function(template){
                                    if(template.item.name === templateName){
                                        that.setSelected(template.item);
                                        return false;
                                    }
                                }, that);
                            },
                            function(response) {
                                console.error(response);
                            }
                        );
                    }
                }
            }
于 2018-06-01T15:06:00.723 回答