如何在另一个匿名函数中调用匿名函数

时间:2015-08-28 22:51:26

标签: javascript arcgis-js-api

我有一个像这样的JS代码,我在photos中为map.on("load", function() {}变量分配了一个匿名函数,现在似乎photos永远不会调用!因为即使我尝试做一个简单的console.log("Is This working")它也没有加载日志!

 var photos;
 map.on("load", function() {
   domStyle.set(query("a.action.zoomTo")[0], "display", "none");
   photos = function(){
     for (var i = 0; i < projects.length; i++) {
       var point = new Point(projects[i].Longitude, projects[i].Latitude);
       var pointSymbol = new SimpleMarkerSymbol(); 
       pointSymbol.setStyle(SimpleMarkerSymbol.STYLE_CIRCLE);
       pointSymbol.setSize(9);
       var pointInfoTemplate = new InfoTemplate(); 
       pointInfoTemplate.setTitle("Project Details");
       pointInfoTemplate.setContent('   ');
       var pointGraphic = new Graphic(point, pointSymbol).setInfoTemplate(pointInfoTemplate);
       points.push(pointGraphic);
     }
     for (i = 0; i < points.length; ++i) {
       map.graphics.add(points[i]);
     }
     console.log(points);
   };
   photos.then(addClusters, error);
 });

请告诉我为什么这不起作用?

由于

  

更新

  map.on("load", function() {
  domStyle.set(query("a.action.zoomTo")[0], "display", "none");
  photos = function(){
    for (var i = 0; i < projects.length; i++) {

    var point = new Point(projects[i].Longitude, projects[i].Latitude);
    var pointSymbol = new SimpleMarkerSymbol(); 
    pointSymbol.setStyle(SimpleMarkerSymbol.STYLE_CIRCLE);
    pointSymbol.setSize(9);
    var pointInfoTemplate = new InfoTemplate(); 
    pointInfoTemplate.setTitle("Project Details");
    pointInfoTemplate.setContent('   ');
    var pointGraphic = new Graphic(point, pointSymbol).setInfoTemplate(pointInfoTemplate);
    points.push(pointGraphic);
}
for (i = 0; i < points.length; ++i) {
    map.graphics.add(points[i]);
}
console.log(points);
};
    photos().then(addClusters, error);

});

1 个答案:

答案 0 :(得分:0)

您永远不会调用photos函数。请确保在变量名称后面加上括号以使其执行,例如photos()。此外,照片功能不会返回任何内容,因此.then()将失败。