【发布时间】:2021-03-03 22:49:54
【问题描述】:
我在 Angular v7 中工作。以下是我的后台回复
[
{'type':'ex1','color':'red','extratype':'x'},
{'type':'ex1','color':'yellow','extratype':'x'},
{'type':'ex1','color':'blue',extratype:'f'},
{'type':'ex1','color':'orange',extratype:'f'},
{'type':'ex2','color':'gray','extratype':'r'},
{'type':'ex2','color':'pink','extratype':'r'},
{'type':'ex2','color':'purlple',extratype:'v'},
{'type':'ex2','color':'green',extratype:'v'},
]
我将此响应存储在 html 选项中,如下所示:
这是ts文件
responsebackend;
results: any[] = [];
types: [] = [];
extratypes: [] = [];
ngOnInit(){
http.get(url)
.subscribe(res => this.responsebackend = res)
}
filter(){
this.results = this.filterCode(this.resposebackEnd);
}
filterCode(res){
let filtered: any[] = [];
res.forEach(val => {
filtered.push(val)
}
return filtered;
}
this.types = ['ex1','ex2'];
this.extratype = ['x','f','r','v'];
这是ts代码
<label for="types">TYPES</label>
<select name="types">
<option *ngFor="let t of types">{{t}}</option>
</select>
<label for="extratypes">extra TYPES</label>
<select name="types">
<option *ngFor="let ex of extratypes">{{ex}}</option>
</select>
<label for="results">RESULTS</label>
<select name="results">
<option *ngFor="let r of results.color">{{r}}</option>
</select>
如果我选择例如 types ex1 和 extratypes f 我想在结果选项 html 标记中看到我只想看到 types ex1 和 extratypes @ 的颜色987654332@
【问题讨论】:
标签: arrays angular object options