onChange 不足以触发来自 Dojo Combobox 的查询 [英] onChange not sufficient to trigger query from Dojo Combobox
问题描述
这与这篇文章密切相关:是否有 onSelect 事件或 HTML
this is closely related to this post: Is there an onSelect event or equivalent for HTML <select>?
...但专门针对 Dojo ComboBox ..(我正在使用带有 ArcGIS JSAPI 的 Dojo).我有三个组合框,它们使用由下拉列表中的选择触发的查询来填充后继者.我的问题是,如果第二个组合框选择保持不变,则不会触发查询.我曾尝试使用 onblur 和其他几个事件代替 onchange,并尝试在 JS 中重置选择的值,但都没有奏效.该值已重置,但组合框仍然表现为相同的值,因此 onchange 不起作用.我尝试了上面链接中的许多方法,但没有一个对我有用.据我所知,我的组合框不会生成任何 selectedIndex.有什么建议?谢谢,J
...but specifically for the Dojo ComboBox..(I am using Dojo w/ ArcGIS JSAPI). I have three combo boxes, which populate the successors using queries triggered by the selections from the dropdown list. My problem is that if the second combobox selection remains the same, the query is not triggered. I have tried using onblur and several other events instead of onchange, and tried to reset the value of the selection in JS, but neither has worked. The value is reset but the combobox still acts as if the same value is there, so onchange does not work. I tried many of the methods in the link above, but none worked for me. As far as I can tell, my comboboxes do not generate any selectedIndex. Any suggestions? Thanks, J
推荐答案
所有三个 dijit dijit/form/Select
、dijit/form/FilteringSelect
和 dijit/form/ComboBox
子类 dijit/_HasDropDown
并为它们添加一个属性 dropDown
:
All three dijits dijit/form/Select
, dijit/form/FilteringSelect
and dijit/form/ComboBox
subclass dijit/_HasDropDown
and that adds them a property 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:
What you want is to listen on this dropDown
widget. The problem is that in the case of ComboBox
and FilteringSelect
this widget dijit/form/_ComboBoxMenu
gets instantiated lazily, i.e. when you open popup for the first time. So you need to hook to opening dropDown in the first place and then add onClick
event listener to the 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
存在并且您可以在它的 dropDown 上监听 onExecute
dijit/Menu
立即:
It's a bit easier when working with dijit/form/Select
, because dropDown
exists and you can listen to onExecute
on its dropDown dijit/Menu
immediately:
select.dropDown.on("execute", function() {
setTimeout(function() {
console.log("value:", select.get("value"))
});
});
在 jsFiddle 上查看所有三个操作:http://jsfiddle.net/phusick/Hp5jr/
See all three in action at jsFiddle: http://jsfiddle.net/phusick/Hp5jr/
这篇关于onChange 不足以触发来自 Dojo Combobox 的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!