this.venuelist有类型的地点
venuelist:Venue[] = [];
类型Venue
在其上具有属性neighborhood
。
我有以下循环
for(let venue in this.venuelist){
let remove = false;
if(this.filters.neighborhood != ''){
if(venue.neighborhood != this.filters.neighborhood){
remove = true;
}
}
}
calling venue.neighborhood called in the second `if statement` is not working
错误是:属性"邻域"在类型'字符串上不存在。
为什么?为什么必须这样做。为什么它不能很好?我该如何使其位置不错?
for(let venue in this.venuelist){}
for ... in不会迭代数组项,它在传递的对象的键上迭代。您应该使用 for...of
for(let venue in this.venuelist){
let remove = false;
if(this.filters.neighborhood != ''){
if(this.venuelist[venue].neighborhood != this.filters.neighborhood){
remove = true;
}
}
}