Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Get response data from outside of esriRequest callback

I am trying to get data from rest service using 'esri/request'. My question is how to get response data from this request and use it outside of this in other function. But do not realize how it's possible under below fromOutSide() without using window variable.

https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html

Finally found way to get variables from outside of .then using lang.hitch Code in below one

define([
    'dojo',
    'dojo/_base/declare',
    'jimu/BaseWidget',
    'dojo/_base/array',
    'dojo/_base/lang',
    'esri/request'
],
function(
    dojo,
    declare,
    BaseWidget,
    array,
    lang,
    esriRequest,
) {
    // Run

    this.getMapService;


    getMapService: function() {
        var requestHandle = esriRequest({
            url: "https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer/0?f=pjson",
            content: {
                f: "json"
            },
            handleAs: "json",
            callbackParamName: "callback"
        });
        requestHandle.then(this.requestSucceeded, this.requestFailed);
        
    },

    requestSucceeded: function(response, io) {
        let responseVar = response;
        console.log(responseVar);
    },

    requestFailed: function(error, io) {
        console.log(error);

    },

    fromOutSide: function() {
        // ? ? ? ?
        console.log(myVar);

    }

});




Updated code: After lang.hitch I was able to use my variables inside .then 
=========================================================


define([
    'dojo/_base/lang',
    'esri/request'
  ],
  function (
    lang,
    esriRequest
  ) {
    return declare([BaseWidget], {
      
      getWindDirection: function () {
          this.requestHandleNode.innerHTML = "";
          
          requestArgs = {
          url: this.config.windDirRestUrl,
          content: {
            f: "json"
            },
          handleAs: "json",
          callbackParamName: "callback",
            };
          
          esriRequest(requestArgs).then(lang.hitch(this, function (response) {
                                            this.requestSucceeded(response);
                                        }),
                                        lang.hitch(this, function (error) {
                                            this.requestFailed(error);
                                        })
            );               
      },
      
      requestSucceeded: function (response, io){
          this.showWindDirection(response);

      },
        
      requestFailed: function (error){
          console.log(error);
          
      },
      
      showWindDirection: function (response){
          console.log(response)
            
      }
      
    });
  });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda