如何在Dojo的ComboBox上捕获打开的事件?

时间:2014-09-25 17:09:01

标签: dojo dijit.form

我想知道是否已打开组合框并在从商店加载数据时调用显示进度条的函数。我已经检查了API但是没有找到任何适合我正在做的事情的事件。

修改

我想要做的是在从商店中填充组合框时启动进度条。我已经使用组合框和进度条(自定义类)和"装饰"创建了一个小部件。具有aspect.before的openDropDown函数。这是我写的代码:

    postCreate: function() {
        this.inherited(arguments);
        aspect.before(
            this.comboBox, 'openDropDown',
            lang.hitch(this, function(){
                this.progressBar.increase();
            })
        );
        on(
            this.comboBox,
            'search',
            lang.hitch(this.progressBar, 'decrease')
        );
    }

但似乎没有使用正确的progressBar对象。

1 个答案:

答案 0 :(得分:0)

听起来你正在寻找类似“onOpen”事件的东西。从Dojo 1.10开始Dijit / Combobox小部件不支持与您描述的事件类似的事件,但它确实支持许多可能符合您要求的其他事件。

我建议查看api以获取可能的事件列表:http://dojotoolkit.org/api/

但是,以下代码将创建一个自定义的“onOpen”事件,就像您所描述的那样。我提供了一个演示这个新事件的jsfiddle

http://jsfiddle.net/kagant15/z4nvzy44/

var comboBox = new ComboBox({
    id: "stateSelect",
    name: "state",
    value: "California",
    store: stateStore,
    searchAttr: "name"
}, "stateSelect")

// grab the existing openDropDown method
var openDropDownFunction = comboBox.openDropDown;
newFunction = function(){
    topic.publish("openDropDown") // add the custom "openDropDown" event trigger
    return openDropDownFunction.apply(this);
}

// replace the old comBox method will our new function
comboBox.openDropDown = newFunction;

// Subscribe to the custom openDropDown event and do something when it fires
topic.subscribe("openDropDown", function(){
    console.log("Open Drop Down even trigger");
});