所以我有一个函数,它接受一个id并通过promise返回相应的属性映射。所以我做了一个循环,并用我所有的it迭代我的函数,但它从不在循环之外执行代码。
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作为键,属性数组作为值。这将按预期进行。
这就是我使用该函数的方式
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,并执行其余代码。谢谢!
发布于 2018-06-01 21:02:38
现在状态
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)
}
https://stackoverflow.com/questions/50642751
复制相似问题