所有三个 dijit和子类dijit/form/Select
,并为它们添加了一个属性:dijit/form/FilteringSelect
dijit/form/ComboBox
dijit/_HasDropDown
dropDown
// dropDown: [protected] Widget
// The widget to display as a popup. This widget *must* be
// defined before the startup function is called.
dropDown: null
你想要的是听这个dropDown
小部件。问题是,在这种情况下ComboBox
,FilteringSelect
这个小部件dijit/form/_ComboBoxMenu
被懒惰地实例化,即当你第一次打开弹出窗口时。因此,您需要首先挂钩打开 dropDown,然后将onClick
事件侦听器添加到 dropDown:
var signal = aspect.after(comboBox, "openDropDown", function() {
comboBox.dropDown.on("click", function(node) {
console.log("value:", comboBox.get("value"));
console.log("selectedIndex:", domAttr.get(node, "item")); // <= this is not an identifier
}
signal.remove(); // remove aspect so it called only once
}
使用时会更容易一些dijit/form/Select
,因为存在并且您可以立即在其下拉列表dropDown
中收听:onExecute
dijit/Menu
select.dropDown.on("execute", function() {
setTimeout(function() {
console.log("value:", select.get("value"))
});
});
在 jsFiddle 上查看所有三个操作:http: //jsfiddle.net/phusick/Hp5jr/