Java GWT。以编程方式在 ListBox 上触发 ChangeEvent。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9667499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GWT. Fire ChangeEvent on ListBox programmatically.
提问by MyTitle
I want to programmatically fire ListBox's ChangeEvent
. I found function, but dont understand what type of parameter i need to pass:
我想以编程方式触发 ListBox 的ChangeEvent
. 我找到了函数,但不明白我需要传递什么类型的参数:
DomEvent.fireNativeEvent(NativeEvent - where???, listBox());
采纳答案by Strelok
You can fire a native ChangeEvent on a widget using:
您可以使用以下方法在小部件上触发本机 ChangeEvent:
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), yourListBox);
回答by Oleksandr_DJ
It is old question, but I want to share my solution, because it is only one that works for me(gwt.version= 2.6.1 and com.github.jdramaix gwtchosen version = 1.2.0)
这是一个老问题,但我想分享我的解决方案,因为它只对我有用(gwt.version= 2.6.1 和 com.github.jdramaix gwtchosen version = 1.2.0)
public class ChosenListBoxNew extends ChosenListBox {
public ChosenListBoxNew() {
super();
}
public void fireUpdateEvent(){
ensureChosenHandlers().fireEvent(new ChosenChangeEvent(this.getValue(), this.getSelectedIndex(), null));
}
}
And you can fire update event by calling fireUpdateEvent() of new class:
您可以通过调用新类的 fireUpdateEvent() 来触发更新事件:
moduleSelectionLst.setSelectedIndex(-1); //Update selected value
moduleSelectionLst.update(); //Update UI
moduleSelectionLst.fireUpdateEvent(); // Fire update event
回答by user3132194
It is possible to fire event using JSNI:
可以使用 JSNI 触发事件:
public native void fireOnChange(String elementId)/*-{
var element = $doc.getElementById(elementId);
if ( element )
element.onchange();
}-*/;