this.venuelist有类型Venue
venuelist:Venue[] = [];
类型Venue
上有属性neighborhood
。
我有以下for循环
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
错误是:'string'类型中不存在属性'邻域'。
为什么?为什么必须这样做。为什么它不能玩得好听?我如何让它变得更好?
答案 0 :(得分:1)
for(let venue in this.venuelist){}
for ... in doesn迭代数组项,它迭代传入的对象的键。你应该使用for...of
答案 1 :(得分:0)
for(let venue in this.venuelist){
let remove = false;
if(this.filters.neighborhood != ''){
if(this.venuelist[venue].neighborhood != this.filters.neighborhood){
remove = true;
}
}
}