简体   繁体   中英

How to open dojo widget that inherits from dijit/_HasDropDown programmatically from enclosing widget?

I have the following custom dojo widget:

<div class="${baseClass}">
    <div data-dojo-type="dijit/TitlePane" data-dojo-props="title:'${prefixTitle}', open:false" id="titleNodePane">
        <div id="container"
        class="${baseClass}Container"
        data-dojo-attach-point="containerNode"></div>
    </div>
</div>

With this code:

/**
 * Javascript for ExpandableSearchComponent
 */
define([ "dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin",
        "dojo/text!./templates/ExpandableSearchComponent.html",
        "dijit/TitlePane", "dijit/_WidgetsInTemplateMixin", "dijit/registry",
        "dojo/on", "dojo/aspect", "dojo/_base/lang" ], function(declare,
        _WidgetBase, _TemplatedMixin, template, TitlePane,
        _WidgetsInTemplateMixin, registry, on, aspect, lang) {

    return declare([ _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ], {
        templateString : template,
        prefixTitle : "",
        containedWidgetId : "",
        that : this,

        startup : function() {
            this.inherited(arguments);
            var containedWidget = registry.byId(this.containedWidgetId);
            var titlePane = registry.byId("titleNodePane");
            this.own(on(titlePane, "Show", function() {

                containedWidget.openDropDown();

            }.bind(containedWidget)));
            //Other logic

        }
    });

});

It is declared like this:

<div data-dojo-type="js/widgets/ExpandableSearchComponent"                                  
    data-dojo-props="prefixTitle: 'Name: ', containedWidgetId: 'machineSearchView.name'">   
<!-- Other elements including the machineNameStore-->                                                          
    <div data-dojo-type="dijit/form/ComboBox"                                               
        data-dojo-props="store:machineNameStore, searchAttr:'name', value:'${MachineName}'" 
        name="machineSearchView.name" id="machineSearchView.name"></div>                    
</div>                                                                                      

It works almost perfectly, except for 1 thing: the on(titlePane, "Show", function(){}) . This is intended to open the dropdown of the contained widget extending _HasDropDown. I'm getting the error Uncaught TypeError: Cannot read property 'domNode' of null on line 139 of _HasDropDown. Apparently, this.dropDown isn't being set until the TitlePane has fully expanded, which breaks openDropDown() .

Is there a way to fix this?

_HasDropDown混合还具有loadAndOpenDropDown()函数,如果不存在该下拉列表,则将其创建,然后将其打开。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM