Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何链接;“范围变化”;及;更新结束“;Dojo中的事件?_Javascript_Events_Dojo - Fatal编程技术网

Javascript 如何链接;“范围变化”;及;更新结束“;Dojo中的事件?

Javascript 如何链接;“范围变化”;及;更新结束“;Dojo中的事件?,javascript,events,dojo,Javascript,Events,Dojo,在ArcGIS JS API中,当数据块更改后的处理完成时,我需要触发类的一个方法。我没发现有什么特别的活动范围更改在数据尚未加载时过早触发更新结束也是由我想要调用的函数触发的,这会形成一个无休止的循环。所以我需要的是把这两件事联系起来,第二件就一次。但是怎么做呢 我的大多数活动如下所示: this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo))); this.events.push(on(this.

在ArcGIS JS API中,当数据块更改后的处理完成时,我需要触发类的一个方法。我没发现有什么特别的活动<代码>范围更改在数据尚未加载时过早触发<代码>更新结束也是由我想要调用的函数触发的,这会形成一个无休止的循环。所以我需要的是把这两件事联系起来,第二件就一次。但是怎么做呢

我的大多数活动如下所示:

this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
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)));
这不适用于事件链接,因此我需要以其他方式创建链接的事件。我所尝试的:

_foo: function () {
    function fooEvent() {
        this._bar();
        dojo.disconnect(updateHandle);
    }
    var updateHandle = dojo.connect(map, "onUpdateEnd", fooEvent());
}
\u bar
是我希望在数据块更改结束时运行的方法。但是,事件处理程序中的
this
表示其他内容,而不是包含函数的类。我还尝试了我在
declare
语句中声明的类名,但没有成功

\u foo()
\u bar()
在同一个类中(我们称之为
“foobar/baz”
)。然而,
fooEvent()
的内部并不像我所希望的那样是它的子类——当我尝试在其中使用
this.inherited
时,它是未定义的。我尝试的另一种方法是向处理程序添加
event
参数,但它也是未定义的。因此,除非有更好的方法,否则我需要了解如何获取
“foobar/baz”
类的对象

我尝试的另一种方法是再次使用
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));

它们都没有返回任何明确的错误,尽管
\u bar()
方法似乎工作了一段时间,但现在不起作用-这对于前面的三个方法都是正确的。我不明白这些侦听器是做什么的。

我通过展平事件侦听器解决了这个问题。首先,我创建了一个标志
\u reloadFlag
,在构造函数中初始化为
false
,然后每当我想调用
\u bar
时,就将其更改为
true
,就像在
\u foo
中一样
\u bar
现在开始测试
\u reloadFlag
将其设置为
false
或不返回任何内容。事件侦听器现在如下所示:

this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
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)));

你是说方法_foo:在类a中声明,而你的_bar()方法在类B中声明,例如?@bRIMOsBor:都在同一个类中。我通常只是使用它来引用其中的其他方法和属性。