javascript - Initializing object with asynchonous request -


यह मेरी ऑब्जेक्ट परिभाषा है:

  फ़ंक्शन ड्रिल्ड लेयर (sourceLayerName, sourceTableName, targetLayerName, targetFieldName , ऑपरेटर्स, बेसलेयर = फॉल्स) {this.sourceLayerName = sourceLayerName; This.sourceTableName = sourceTableName; This.targetLayerName = targetLayerName; This.targetFieldName = targetFieldName; This.operators = ऑपरेटरों; This.baseLayer = बेसलेयर; this.targetLayerId; this.drilledLayerId; this.selectedCode; This.redraw = false; this.getTargetLayerId (); // इस फ़ंक्शन को इस प्रारंभिकता को प्रारंभ करना चाहिए। लक्षित लिअरआईडी} डॉरल लेयर। प्रोटोटाइप .getTargetLayerId = फ़ंक्शन () {$ .soap ({url: 'https: //url/version_4.8/services/MapService', विधि: 'getLayersIdByName', appendMethodToURL : गलत, डेटा: {mapInstanceKey: mapKey, layerName: this.targetLayerName,} त्रुटि: कार्य () {चेतावनी ("त्रुटि getLayersIdByName");}, सफलता: फ़ंक्शन (सोप रीस्पॉन्स) {layerId = soapResponse.toJSON ()। .getLayersIdByNameResponse.getLayersIdByNameReturn.getLayersIdByNameReturn.text; this.targetLayerId = layerId;}}); }   

इस तरह से मैं वस्तु बना रहा हूं:

  drillCs = नया ड्रिललायर ("ड्रिलेड सीएस", "सीएस_फ्रांको_जैरल.ए.बी.", "आरए_जैरल", "Code_RA", "=")   

अगर मैं ड्रिल सी एस ऑब्जेक्ट में देखता हूं, तो कोई लक्षित लेटरआईडी प्रॉपर्टी परिभाषित नहीं होती है, लेकिन मुझे पता है कि साबुन अनुरोध सफलतापूर्वक किया गया था क्यों?

यह जावास्क्रिप्ट में ज्यादातर द्वारा फ़ंक्शन को कैसे कहा जाता है । यह के दौरान सफलता कॉलबैक आपके getTargetLayerId फ़ंक्शन पर कॉल के दौरान यह जैसा नहीं होगा, आप इसे याद रखना होगा।

इस मामले में, सबसे आसान तरीका शायद एक चर के साथ है:

  DrilledLayer.prototype.getTargetLayerId = function () {var layer = this; // & lt; === इसे $ .soap ({url: 'https: //url/version_4.8/services/MapService', सेट करें: 'getLayersIdByName', appendMethodToURL: गलत, डेटा: {mapInstanceKey: mapKey, layerName : This.targetLayerName,}, त्रुटि: कार्य () {चेतावनी ("त्रुटि getLayersIdByName");}, सफलता: फ़ंक्शन (सोप रीस्पॉन्स) {layerId = साबुन। TargetLayerId = layerId; // & lt; === इसे प्रयोग करें}});   

अधिक (मेरे ब्लॉग पर) :

  • अलग से, बेशक, आप एसिंक कॉलबैक आग (जो कि नया कॉल रिटर्न के कुछ समय बाद होगा) तक ठीक से नहीं दिखाई देंगे, लेकिन आप इस के async पहलू के साथ सहज महसूस करते हैं।

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

Matlab: Transfer variable from GUI to Base Workspace and new Variables (Static Workspace, Script, Creating new Variables) -