在ArcGIS JS API中,當擴展盤更改完成後,我需要觸發我的類的方法。我沒有爲此找到任何特殊事件。當數據尚未加載時,extent-change
觸發得太早。 update-end
也是由我想調用的函數觸發的,使得無限循環。所以我需要的是把兩個事件聯繫在一起,第二個只是一次。但是如何?如何鏈接Dojo中的「extent-change」和「update-end」事件?
我的大多數事件是這樣的:
this.events.push(on(this.map, "extent-change", lang.hitch(this, this._foo)));
這不適合於事件聯繫起來,所以我需要鏈接的情況下一些其他的方式。我已經試過:
_foo: function() {
function fooEvent() {
this._bar();
dojo.disconnect(updateHandle);
}
var updateHandle = dojo.connect(map, "onUpdateEnd", fooEvent());
}
_bar
是我想要的程度變化結束時運行的方法。然而,事件處理程序中的this
意味着別的東西,而不是包含該功能的類。我也嘗試了我在declare
聲明中聲明的類名,但沒有運氣。
_foo()
和_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));
他們沒有返回任何明確的錯誤,雖然_bar()
方法似乎工作一段時間,這不是現在不工作 - 對於之前的三次都是如此。我不明白這些聽衆是做什麼的。
您的意思是方法_foo:在類A中聲明的方法和類B中的_bar()方法例如? –
@bRIMOsBor:都在同一個班級。我通常只是用它來引用其他方法和屬性。 –