Custom dojo Dropdown widget by inheriting _HasDropdown and _AutoCompleterMixin

元气小坏坏 提交于 2019-12-25 04:05:08

问题


I am trying to do a Custom Dropdown that will query some of My Own service and update its Drop Down Menu accordingly. I am following the example on http://livedocs.dojotoolkit.org/dijit/_HasDropDown But that doesn't describe how to create the dom for dropdown container.

Do I need to set this.dropDown to some dijit._Widget in ctor ? If another dijit._widget needs to be created first ? If yes I know How to update values By data-dojo-attach-point But in case of drop down it will be a collection that needs to be updated. Is there any such tool in dojo that can handle collections for this kind of situation ? otherwise manually handling clearing/filling/event-handleing on each of this dropdown elements will easily get messy.


回答1:


I created a custom widget that is what is displayed on the form. Within this widget, I override the openDropDown and closeDropDown functions. In my case, the dropdown was complex enough that it was easier to destroy it on close and recreate each time the user

dojo.declare("TextboxWithCustomDropdown", 
    [dijit.form.ValidationTextBox, dijit._HasDropDown], {

    openDropDown: function() {  
        if(!this.dropDown) {
            var _s = this;

            this.dropDown = new MyCustomDropDown({...});
            this.dropDown.connect(this.dropDown, 'onChange', function(val) {
                _s.closeDropDown();
                _s.attr('value', val);              
            });
        }
        this.inherited(arguments);
    },
    closeDropDown: function() {
        this.inherited(arguments);
        if (this.dropDown) {
            this.dropDown.destroy();
            this.dropDown = null;
        }
    }
});

dojo.declare("MyCustomDropDown", [dijit._Widget, dijit._Templated], {

    templateString: ...

    // when the user makes their selection in the dropdown, I call the onChange 
    // function, and the textbox is listenting on this
    onChange: function(/*Object*/ value) {}
}


来源:https://stackoverflow.com/questions/10534076/custom-dojo-dropdown-widget-by-inheriting-hasdropdown-and-autocompletermixin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!