如何链接“范围变化”和“更新结束”事件在Dojo? [英] How to link "extent-change" and "update-end" events in Dojo?
问题描述
在ArcGIS JS API中,在扩展盘更改完成后的处理中,我需要触发一个类的方法。我没有找到任何特殊的事件。当数据尚未加载时,$ code> extent-change 触发得太早了。 update-end
也由我想要调用的函数触发,使得无限循环。所以我需要的是将两个事件联系起来,第二个只是一次。但是如何?
In ArcGIS JS API I need to trigger a method of my class when the processing after an extent change is complete. I didn't find any special event for this. extent-change
triggers too early, when the data are not loaded yet. update-end
is triggered also by the function I want to call, making an endless loop. So what I need is to link the two events together, the second one just once. But how?
我的大部分活动如下所示:
Most of my events look like this:
this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
这不适合事件链接,所以我需要使链接的事件有其他的方式。我尝试过:
This is not suitable for event linking, so I need to make the linked event some other way. What I've tried:
_foo: function () {
function fooEvent() {
this._bar();
dojo.disconnect(updateHandle);
}
var updateHandle = dojo.connect(map, "onUpdateEnd", fooEvent());
}
_bar
是方法我想在范围变化结束时运行。但是,事件处理程序中的这个
意味着别的东西,而不是包含该函数的类。我也尝试了在声明
声明中声明的类名,但没有运气。
_bar
is the method I want to run on the end of the extent change. However, this
in the event handler means something else, not the class containing the function. I also tried the classname I declared in the declare
statement, but with no luck.
_foo()
和 _bar()
在同一个类中(让我们称之为foobar / baz code>)。但是,在
fooEvent()
的内部不是我的子类,因为我希望 - 当我尝试使用 this.inherited
在它内,它是未定义的。我尝试的另一种方法是向处理程序添加事件
参数,但它也是未定义的。所以除非有更好的方法,否则我需要了解如何获取foobar / baz
类的对象。
_foo()
and _bar()
are in the same class (let's call it "foobar/baz"
). However, inside of the fooEvent()
is not its subclass as I hoped - when I try to use this.inherited
within it, it's undefined. Another way I try is to add event
argument to the handler, but it's undefined as well. So unless there is some better way, I need to understand how to get the object of "foobar/baz"
class.
另一种尝试方法是使用 lang.hitch
,以下列方式之一:
Another way I tried was to use lang.hitch
once more, in one of the following ways:
//through the cluster event
var updateHandle = dojo.connect(map, "onUpdateEnd", lang.hitch(this, clusterEvent));
//or directly calling _bar()
var updateHandle = dojo.connect(map, "onUpdateEnd", { langh:lang.hitch(this, this._bar), disc:dojo.disconnect(updateHandle)});
//or through on, leaving a rouge event listener
dojo.on(map, "onUpdateEnd", lang.hitch(this, this._bar));
没有一个返回任何清除错误,虽然 _bar()
方法似乎工作了一段时间,它现在不起作用 - 对于以前的所有三个都是如此。我不明白这些听众的作用。
None of them returns any clear error and though the _bar()
method seemed to work for some time, it doesn't work now - this is true for all three of the previous. I don't understand what these listeners do.
推荐答案
我通过展平事件听众来解决这个问题。首先,我将一个标志 _reloadFlag
,在构造函数中初始化为 false
,然后更改为只要我想要调用
_bar
,就像在 _foo
中一样。 _bar
现在开始测试 _reloadFlag
将其设置为 false
或什么也不返回事件侦听器现在看起来像这样:
I solved this issue by flattening the event listeners. First, I made a flag _reloadFlag
, initialized in the constructor as false
and then changed to true
whenever I want to call _bar
, like in _foo
. _bar
now starts with a test of _reloadFlag
either setting it to false
or returning nothing. The event listeners now look like this:
this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
this.events.push(on(this.map, "update-end", lang.hitch(this, this._bar)));
这篇关于如何链接“范围变化”和“更新结束”事件在Dojo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!