首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在带有promises的循环后不执行任何代码

在带有promises的循环后不执行任何代码
EN

Stack Overflow用户
提问于 2018-06-01 19:48:20
回答 1查看 51关注 0票数 0

所以我有一个函数,它接受一个id并通过promise返回相应的属性映射。所以我做了一个循环,并用我所有的it迭代我的函数,但它从不在循环之外执行代码。

代码语言:javascript
复制
async getProps(dbId) {
    const properties = Viewer.properties //creates an empty map
    return new Promise((resolve, reject) => {
            let prom = new Promise((resolve, reject) => {
                this.gui.getProperties(
                    dbId,
                    args => {
                        console.log('properties', args)
                        resolve(args.properties)
                    },
                    reject
                )
            })

            prom.then(props => {
                properties.set(dbId, props)
                resolve(properties.entries())
            })
            console.log('properties', properties)
        }
    )
}

我想要的是创建一个映射,其中ID作为键,属性数组作为值。这将按预期进行。

这就是我使用该函数的方式

代码语言:javascript
复制
async getConcreteIds() {
    let wallfloorids = this.getWallIds().concat(this.getFloorIds());
    // let concreteIds = [];
    for(let id of wallfloorids) {
        let p1 = await this.view.getProps(id);
        console.log(p1);
    }
    console.log("Hello");
}

我遍历我的ID并调用getProperties函数,它会按预期记录地图。但它永远不会离开循环。wallfloorids有52个条目,所以它不是一个无限循环。我认为我的getProperties函数的结构是原因,但我不知道要更改什么。我尝试更改结构,但随后它返回一个空的map,并执行其余代码。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-01 21:02:38

现在状态

代码语言:javascript
复制
getProperties(dbId) {
    const properties = Viewer.properties
    return new Promise((resolve, reject) => {
        this.gui.getProperties(
            dbId,
            args => {
                resolve(args.properties)
            },
            reject
        )
    })

}


async getConcreteIds() {
    let wallfloorids = this.getWallIds().concat(this.getFloorIds());
    let concreteIds = [];
    for (let id of wallfloorids) {
        let p1 = await this.view.getProperties(id);
        console.log(p1);
            for (let prop of p1){
                if (prop.displayCategory === "Materialien und Oberflächen" && prop.displayValue.contains("Concrete"))
                    concreteIds.push(id);
            }
    }
    return concreteIds;
}

onlyConcrete() {
    let ids = [];
    const concreteIds = this.getConcreteIds();
    console.log(concreteIds);
    this.viewer.isolateById(concreteIds)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50642751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档