我创建了一个自定义小部件,它显示在表单上。在这个小部件中,我覆盖了openDropDown
andcloseDropDown
函数。在我的情况下,下拉列表足够复杂,以至于每次用户关闭时都更容易将其销毁并重新创建
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) {}
}