Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在地图中使用wait?_Javascript_Typescript - Fatal编程技术网

Javascript 如何在地图中使用wait?

Javascript 如何在地图中使用wait?,javascript,typescript,Javascript,Typescript,有一系列图层: this.layers = [ new ThematicLayers( this.userRoles, this.layersManager, this.map ), new CommonLayers( this.userRoles, this.layersManager, this.map ), ]; 和抽象: export

有一系列图层:

this.layers = [
      new ThematicLayers(
        this.userRoles,
        this.layersManager,
        this.map
      ),
      new CommonLayers(
        this.userRoles,
        this.layersManager,
        this.map
      ),
    ];
和抽象:

export abstract class Layer {
  protected layers: Promise<any> = Promise.resolve(null);

  protected layerGroup: LayerGroup;

  protected grouppedNodes: Map<ITreeNode, ITreeNode[]>;

  abstract load(): Promise<LayerGroup>;

  abstract prepareLayers<T>(layers: T[]): T;

  abstract hasPermission(): boolean;

  abstract createLayersGroup(): void;
 
  get group() {
    return this.layerGroup;
  }

  get stateLayers() {
    return this.reonMap.state;
  }

}
问题在线:

layer.prepareLayers(await layer.load());

如何在映射中使用wait?

正确的方法是在映射回调之前添加一个异步:

async GetLayerGroups():Promise{
返回此.layers.map(异步(层:层)=>{
layer.prepareLayers(等待layer.load());
layer.createLayersGroup();
返回层组;
});

}
正确的方法是在映射回调之前添加一个异步:

async GetLayerGroups():Promise{
返回此.layers.map(异步(层:层)=>{
layer.prepareLayers(等待layer.load());
layer.createLayersGroup();
返回层组;
});


}
承诺。所有的
帮助都在这里?你能演示一下,如何应用它来代替
map()
?它不会取代
map
。看这回答了你的问题吗?不,我不能使用promise。所有这些都是因为我需要从aboth promises中获得结果,而不是从aboth promises中获得结果,它可以是一个。将
promise。所有
都在这里提供帮助吗?您能否演示,如何使用它来代替
map()
?它不会取代
map
。看这回答了你的问题吗?不,我不能使用promise。所有这些都是因为我需要的结果不是来自aboth的承诺,它可以是一个。为什么你要复制代码并发布它们?区别是什么?区别在于层的异步形式:this.layers.map(异步(层:层)是的,我知道很抱歉,will会尝试编辑答案以使其清晰。不
GetLayerGroups
仍然需要使用
Promise调用。所有
?为什么要复制代码并发布它们?区别是什么?区别是层的异步形式:this.layers.map(异步(层:层)是的,我知道了,很抱歉,will会尝试编辑答案以使其清晰。不
GetLayerGroups
仍然需要使用
Promise调用。所有
layer.prepareLayers(await layer.load());