[英]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
. 每当在
app.parkGrid
单击一行时,我都想调用initializeTrailGrid()
函数。 When I try to run it as it is written I get an error telling me initializeTrailGrid
is not a function. 当我尝试按照编写的方式运行它时,出现错误消息,告诉我
initializeTrailGrid
不是函数。 If I call initializeTrailGrid()
from a define
block in a different file it works fine. 如果我从其他文件中的
define
块调用initializeTrailGrid()
,它将正常工作。 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. 上面显示的代码在文件
myGrid
因此我尝试将javascript/myGrid
放入定义列表中,并使用myGrid.initializeTrailGrid()
进行调用,但这也不起作用。 Is there a way to do this given how the define
block is structured? 给定
define
块的结构,有没有办法做到这一点?
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: 然后,在click事件上调用方法...别忘了初始化类:
var myclass = new Myclass();
app.parkGrid.on('.dgrid-row:click', function(event){
myclass.initializeParkGrid(a, b);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.