IBM Content Navigator。如何在功能打开时运行搜索

时间:2018-06-01 14:55:10

标签: ibm-content-navigator

我们是否可以将搜索配置为在选择搜索功能时自动打开,我认为可以通过配置进行,但我无法找到可以配置它的位置。 它已经讨论过了 https://www.ibm.com/developerworks/community/forums/html/topic?id=fbac6330-f636-4745-924a-a713f4f9a309&ps=50&tags=&query=&filter=&sortBy=&order=asc 但没有答案如何做,只有建议:"你可以用插件编码。" 如何使用插件完成此操作?

1 个答案:

答案 0 :(得分: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);
                            }
                        );
                    }
                }
            }