dojo解析器和使用ArcGIS JS API的TypeError [英] dojo parser and a TypeError using ArcGIS JS API

查看:233
本文介绍了dojo解析器和使用ArcGIS JS API的TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这个错误:

TypeError:'undefined'不是一个函数(评估'parser.parse()')

TypeError: 'undefined' is not a function (evaluating 'parser.parse()')

这是我的代码。

<script> 
    require([
      "esri/map", 
      "esri/layers/FeatureLayer", 
      "esri/dijit/Legend",
      "esri/digit/HomeButton",
      "dojo/_base/array", 
      "dojo/parser",
      "dijit/layout/BorderContainer", 
      "dijit/layout/ContentPane", 
      "dijit/layout/AccordionContainer", 
      "dojo/domReady!"
], function(
  Map, FeatureLayer, Legend, arrayUtils, parser, HomeButton
) {
    parser.parse();

    var map = new Map("map", {
        basemap: "streets",
        center: [-87.702733, 41.998508],
        zoom: 15
    });

    var home = new HomeButton ({
        map: map
    }, "HomeButton");
    home.startup();

  var circuits = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/6", {
    mode: FeatureLayer.MODE_ONDEMAND,
    outFields:["*"]
  });

  var power = new FeatureLayer("http://54.243.188.50:6080/arcgis/rest/services/TYLIN/Streetlights_Pilot/MapServer/2", {
    mode: FeatureLayer.MODE_ONDEMAND,
    outFields:["*"]
  });


  //add the legend
  map.on("layers-add-result", function (evt) {
    var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
      return {layer:layer.layer, title:layer.layer.name};
    });
    if (layerInfo.length > 0) {
      var legendDijit = new Legend({
        map: map,
        layerInfos: layerInfo
      }, "legendDiv");
      legendDijit.startup();
    }
  });

  map.addLayers([circuits, power]);
});

</script>

我已经能够通过分离与Legend部分分开的HomeButton部分来运行。在这个角子里,我必须调用dojo.parser.parse() - 但是它不适用于Legend部分。

I've been able to get this to run by splitting out the HomeButton part separate from the Legend part. In the comer, I have to call dojo.parser.parse() -- but that doesn't work with the Legend part.

我不太明白dojo /解析器的工作原理,所以我很难理解为什么某些部分需要dojo.parser.parse(),而其他部分需要解析器。 parse()。

I don't really understand how the dojo/parser works so it's difficult for me to understand why some parts require dojo.parser.parse() and others require parser.parse().

推荐答案

中有一个问题require() dojo / parser 是您导入的第六个模块,然而,名为 parser 的参数是在第五名,所以他们不匹配。您导入的模块的顺序必须与使用它们的参数相同,所以这是正确的方式:

There is a problem in your require(). dojo/parser is the 6th module you import, however, the parameter named parser is on the 5th place, so they don't match. The order of the modules you import must be the same as the parameters you use them in, so this is the correct way:

require([
      "esri/map", 
      "esri/layers/FeatureLayer", 
      "esri/dijit/Legend",
      "esri/digit/HomeButton",
      "dojo/_base/array", 
      "dojo/parser",
      "dijit/layout/BorderContainer", 
      "dijit/layout/ContentPane", 
      "dijit/layout/AccordionContainer", 
      "dojo/domReady!"
], function(
  Map, FeatureLayer, Legend, HomeButton, arrayUtils, parser
) {

如你所见,我将HomeButton切换到另一个地方现在的模块与参数匹配。

As you see, I switched HomeButton to another place and now the modules match the parameters.


  • esri / map (第一个模块): 地图(函数中的第一个变量)

  • esri / layers / FeatureLayer 第二个模块): FeatureLayer (第二个参数)

  • esri / dijit / Legend (第3个模块):图例(第3个参数)

  • esri / dijit / HomeButton (第4个模块): HomeButton (第4个参数)

  • dojo / _base / array (第5个模块): arrayUtils (第5个参数) (6th module): parser (第6个参数) li>
  • esri/map (1st module): Map (1st variable in function)
  • esri/layers/FeatureLayer (2nd module): FeatureLayer (2nd parameter)
  • esri/dijit/Legend (3rd module): Legend (3rd parameter)
  • esri/dijit/HomeButton (4th module): HomeButton (4th parameter)
  • dojo/_base/array (5th module): arrayUtils (5th parameter)
  • dojo/parser (6th module): parser (6th parameter)

如果您将代码分开,您的代码的原因是因为您可能修复了 require() dojo.parser.parse()的原因是因为旧的旧版代码不使用 require 回调。

The reason why your code works if you seperate them is because you probably fix your require(). The reason why dojo.parser.parse() works is because it's old deprecated legacy code which doesn't use the parameter of the require callback.

这篇关于dojo解析器和使用ArcGIS JS API的TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆