以下是我的代码的简化版本。
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();
});
});
}
};
});
我想在initializeTrailGrid()
中点击一行时调用app.parkGrid
函数。当我尝试在编写时运行它时,我收到一个错误,告诉我initializeTrailGrid
不是函数。如果我从另一个文件中的initializeTrailGrid()
块调用define
,则可以正常工作。上面显示的代码位于文件myGrid
中,因此我尝试将javascript/myGrid
放在定义列表中,并使用myGrid.initializeTrailGrid()
来调用它,但这也不起作用。考虑到define
块的结构如何,有没有办法做到这一点?
答案 0 :(得分:2)
最好创建一个类:
Myclass = function () {
this.initializeParkGrid = function (gridid, gridDiv) {
return app.parkGrid;
}
}
然后,在click事件中,调用方法...不要忘记初始化类:
var myclass = new Myclass();
app.parkGrid.on('.dgrid-row:click', function(event){
myclass.initializeParkGrid(a, b);
});