如何在 Dojo 中 link "extent-change" 和 "update-end" 事件?
How to link "extent-change" and "update-end" events in Dojo?
在 ArcGIS JS 中 API 我需要在完成范围更改后的处理时触发 class 的方法。我没有找到任何特殊事件。 extent-change
触发太早,数据尚未加载时。 update-end
也由我要调用的函数触发,形成无限循环。所以我需要的是 link 把两个事件放在一起,第二个只需要一次。但是怎么办?
我的大部分活动都是这样的:
this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
这不适合事件 linking,因此我需要以其他方式制作 linked 事件。我尝试过的:
_foo: function () {
function fooEvent() {
this._bar();
dojo.disconnect(updateHandle);
}
var updateHandle = dojo.connect(map, "onUpdateEnd", fooEvent());
}
_bar
就是我要的方法,运行就结束了extent的变化。但是,事件处理程序中的 this
表示其他含义,而不是包含该函数的 class。我还尝试了在 declare
语句中声明的 classname,但没有成功。
_foo()
和_bar()
在同一个class中(暂且称它为"foobar/baz"
)。但是,fooEvent()
内部并不是我希望的它的 subclass - 当我尝试在其中使用 this.inherited
时,它是未定义的。我尝试的另一种方法是向处理程序添加 event
参数,但它也是未定义的。所以除非有更好的方法,否则我需要了解如何获取 "foobar/baz"
class.
的对象
我尝试的另一种方法是通过以下方式之一再次使用 lang.hitch
:
//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));
None 其中 returns 有任何明显的错误,虽然 _bar()
方法似乎工作了一段时间,但现在不起作用 - 这三个方法都是如此以前的。我不明白这些听众在做什么。
我通过扁平化事件侦听器解决了这个问题。首先,我制作了一个标志 _reloadFlag
,在构造函数中初始化为 false
,然后每当我想调用 _bar
时更改为 true
,就像在 _foo
中一样。 _bar
现在从 _reloadFlag
的测试开始,将其设置为 false
或不返回任何内容。事件监听器现在看起来像这样:
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)));
在 ArcGIS JS 中 API 我需要在完成范围更改后的处理时触发 class 的方法。我没有找到任何特殊事件。 extent-change
触发太早,数据尚未加载时。 update-end
也由我要调用的函数触发,形成无限循环。所以我需要的是 link 把两个事件放在一起,第二个只需要一次。但是怎么办?
我的大部分活动都是这样的:
this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
这不适合事件 linking,因此我需要以其他方式制作 linked 事件。我尝试过的:
_foo: function () {
function fooEvent() {
this._bar();
dojo.disconnect(updateHandle);
}
var updateHandle = dojo.connect(map, "onUpdateEnd", fooEvent());
}
_bar
就是我要的方法,运行就结束了extent的变化。但是,事件处理程序中的 this
表示其他含义,而不是包含该函数的 class。我还尝试了在 declare
语句中声明的 classname,但没有成功。
_foo()
和_bar()
在同一个class中(暂且称它为"foobar/baz"
)。但是,fooEvent()
内部并不是我希望的它的 subclass - 当我尝试在其中使用 this.inherited
时,它是未定义的。我尝试的另一种方法是向处理程序添加 event
参数,但它也是未定义的。所以除非有更好的方法,否则我需要了解如何获取 "foobar/baz"
class.
我尝试的另一种方法是通过以下方式之一再次使用 lang.hitch
:
//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));
None 其中 returns 有任何明显的错误,虽然 _bar()
方法似乎工作了一段时间,但现在不起作用 - 这三个方法都是如此以前的。我不明白这些听众在做什么。
我通过扁平化事件侦听器解决了这个问题。首先,我制作了一个标志 _reloadFlag
,在构造函数中初始化为 false
,然后每当我想调用 _bar
时更改为 true
,就像在 _foo
中一样。 _bar
现在从 _reloadFlag
的测试开始,将其设置为 false
或不返回任何内容。事件监听器现在看起来像这样:
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)));