由于 listBox 的 onChange 事件处理程序中的繁重处理,GWT UI 未更新
我有一个列表框,在其 onChange() 上,我正在更新另一个列表框。 所以代码就像这样
ListBox l1 = new ListBox();
...some items added to l1..
ListBox l2 = new ListBox();
l2.setEnabled(false);
l1.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
//Show info msg
//Update label text on top of the page with "Loading.."
//..Do some processing here..
L2.setEnabled(true);
L2.getElement().setInnerHTML(html);
}
,除了一个小故障之外,一切正常。 UI 被卡住,并且 l1、l2 和标签在处理完成之前都不会反映更改。 l2 当然会在稍后的时间点反映,但 l1 和信息也不会显示。
我尝试使用 ScheduledDeferred 作为 --
l1.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
//Show info msg
//Update label text on top of the page with "Loading.."
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Overide
public void execute() {
//..Do some processing here..
}
}
L2.setEnabled(true);
L2.getElement().setInnerHTML(html);
}
}
但上面仍然没有帮助,它仍然照常工作。有什么建议吗?
I have a list Box, on whose onChange(), I am updating another listBox.
So the code is something like
ListBox l1 = new ListBox();
...some items added to l1..
ListBox l2 = new ListBox();
l2.setEnabled(false);
l1.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
//Show info msg
//Update label text on top of the page with "Loading.."
//..Do some processing here..
L2.setEnabled(true);
L2.getElement().setInnerHTML(html);
}
This is working all fine, except for one glitch. The UI is stuck and both l1, l2 and label don't reflect the change until the processing is done. l2 would ofcourse reflect at later point of time, but l1 and info aren't showing up either.
I tried using scheduledDeferred as --
l1.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
//Show info msg
//Update label text on top of the page with "Loading.."
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Overide
public void execute() {
//..Do some processing here..
}
}
L2.setEnabled(true);
L2.getElement().setInnerHTML(html);
}
}
But above is still not helping, it's still working as usual. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看 GWT 的 IncrementalCommand可以帮助进行长时间运行的计算。
You could look into GWT's IncrementalCommand which can help with long running calculations.
计划命令执行的操作与前面的代码片段完全相同 - 它执行一些处理,然后更新 UI。您需要做的是首先更新 UI,然后执行处理(希望处理不会锁定浏览器)。
试试这个:
The scheduled command does exactly the same thing as the previous snippet - it performs some processing, then updates the UI. what you need to do is first update the UI, then perform the processing (hopefully the processing doesn't lock up the browser) .
try this: