我真的很困惑,一些行爲,我看到在努力學習道場的AMD樣式的引用。當我實例化我的模塊/對象時,「this」指向我的構造函數中的對象。我調用了一個內部函數,並且該內部函數中的「this」引用了Window對象。所以,當我到達this.attachMapEventHandlers我得到一個「對象[對象全局]有沒有方法'attachMapEventHandlers」錯誤。我究竟做錯了什麼?更新:我發現lang.hitch,這似乎表明,異步性質是什麼絆倒了我,但我對如何實現解決方案相混淆。道場AMD模塊改變的「本」
我的劇本里的index.html:
require(["javascript/layout", "dijit/layout/ContentPane", "dijit/layout/BorderContainer", "dijit/layout/AccordionContainer",
"dojo/dom", "dojo/dom-attr", "dijit/Toolbar", "dijit/form/Button", "dijit/Dialog","dijit/ProgressBar", "dojo/domReady!"],
function (layout, dom, domAttr) {
mapControl = new layout();
layout.js:
define(["dojo/_base/declare"], function(declare) {
return declare(null, {
action:"pan",
activeMeasureTool:"",
aerialLayer:"",
legendLayers:"",
loadedServices:"",
popup:"",
resizeId:0,
constructor: function() {
this.init();
},
init: function() {
require(["esri/map", "esri/config", "esri/SpatialReference", "esri/geometry/Extent"],
function(Map, config, SpatialReference, Extent) {
//custom map requires a proxy to function properly.
esri.config.defaults.io.proxyUrl = "../sdc_devdata/proxy.php";
var spatRef = new SpatialReference(2276);
var startExtent = new Extent(2481416.32087491, 6963246.42495962, 2501196.36936991, 6980267.92469462, spatRef);
var appFullExtent = new Extent(2396699.46935379, 6872369.60195443, 2607745.94404633, 7107335.22319087, spatRef);
map = new Map("map", {extent: startExtent, isZoomSlider:true, logo:false, sliderStyle:"large"});
this.attachMapEventHandlers();
this.createLayers();
this.handleLayerVisibilityChange();
});
},
我很欣賞你的答案。接受第一個 – Shawn