简体   繁体   中英

Calling a javascript function in a define block from a different function in the block

The following is a simplified version of my code.

define ([ 
"dojo/dom",
"dojo/_base/array", 
"dojo/_base/declare",
"dgrid/OnDemandGrid", 
"dgrid/Selection",
"dgrid/Keyboard",
"dijit/form/Button",
"dojo/store/Memory",
"dojo/dom-construct",
"dojo/string",
"esri/layers/FeatureLayer", 
"esri/tasks/query",
"esri/tasks/QueryTask",
"javascript/myUtilities",
"javascript/myCSV",
"javascript/myGrid"
  ], function (  
dom,arrayUtils,declare,Grid,Selection,Keyboard,Button,Memory,domConstruct,dojoString,FeatureLayer,Query,QueryTask, myUtilities, myCSV, myGrid) {  
return {
        initializeParkGrid: function(gridid, gridDiv){
                            //code is here
                            return app.parkGrid;
                            },     
        initializeTrailGrid: function(gridid, gridDiv){
                                //code is here
                            return app.trailGrid;
                            },

        updateParkGrid: function(){     
                                //code is here

                              app.parkGrid.on('.dgrid-row:click', function(event){
                                  initializeTrailGrid();
                              });
                            });
                        }                                   
        };
  }); 

I want to call the initializeTrailGrid() function whenever a row is clicked in the app.parkGrid . When I try to run it as it is written I get an error telling me initializeTrailGrid is not a function. If I call initializeTrailGrid() from a define block in a different file it works fine. The code shown above is in the file myGrid so I tried putting javascript/myGrid in the define list and using myGrid.initializeTrailGrid() to call it but that didn't work either. Is there a way to do this given how the define block is structured?

it's better to create a class:

Myclass = function () {
    this.initializeParkGrid = function (gridid, gridDiv) {
        return app.parkGrid;
    }
}

then, on click event, call method... don't forget to initialize the class:

var myclass = new Myclass();

app.parkGrid.on('.dgrid-row:click', function(event){
   myclass.initializeParkGrid(a, b);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM