ArcGIS中加载模块时dojo/domReady!和dojo/ready的区别

我们在使用ArcGIS Javascript  API开发时,最开始要先加载模块:

<script>
  require(["esri/map", "dojo/domReady!"], function(Map) {
    // code to create the map and add a basemap will go here
  });
</script>

这里有个dojo/domReady!,另外Dojo还有一个dojo/ready,这俩有啥区别呢,esri官网上有这么一段:

The difference between domReady and ready is that the former waits to fire the callback provided to require until the DOM is available while the latter waits for the DOM to be ready and waits for all outstanding require calls to finish. For more information, see the Dojo documentation for dojo/ready. In simple cases, dojo/domReady! should be used. If an app uses parseOnLoad: true, Dojo Dijits, widgets from the Esri library or custom dijits, dojo/ready should be used.

翻译过来就是,domReady是等待所有DOM元素加载完成,再require相关模块;而ready是等待DOM元素加载以及require的相关模块全部加载完成。在一些简单应用场景,用dojo/domReady!就行了;如果应用里需要用到一些组件,微件之类的还是用dojo/ready.

猜你喜欢

转载自blog.csdn.net/wml00000/article/details/82497433