我是一个新开发人员,致力于现有的代码库,现在我的任务是在从芯片列表中选择一个特定的芯片时,显示卡内的所有芯片,但我不太确定如何修改这段代码,所以如果我能得到任何帮助或建议,我将非常感激。
所以现在我们有多张卡,里面有他们自己的芯片,还有一个芯片列表,可以根据他们的芯片过滤卡片。当用户从芯片列表中选择特定的芯片时,它会过滤所有的卡,并且只显示包含所选芯片的卡。
Situation
现在,当从芯片列表中选择特定的芯片时,除了用户选择的一个芯片外,卡内的所有芯片都是消失/过滤的。
试图实现
我仍然希望卡片显示它所包含的每一个芯片,而不仅仅是显示用户选择的内容。
<!--- Cards List -->
<mc-workspace-card-list [workspaces]="filteredPubWorkSpaces"></mc-workspace-card-list>
<!-- Tags List -->
<mat-chip *ngFor="let tag of tagList" [selected]="tag.state"
(click)="tag.state = !tag.state; changeSelected('s', tag.tag)"
[ngStyle]="{'background-color':tag.state? 'mediumturquoise' : '' }">
<img class="super-icon" *ngIf="tag.superTag || tag.type == TagType.super"
src="/assets/images/icons/super-tag-icon.svg">
{{tag.tag}}
</mat-chip>
</mat-chip-list> tagList: Tag[] = [];
chartSearchResults: Chart[] = [];
tagSearch: string[] = [];
filteredPubWorkSpaces = [];
ngOnInit(): void {
var superTags: Tag[] = [];
//get all the tags
this.tagService.getAllTagsByType('super').subscribe((sTags) => {
this.loading = true;
if (sTags) {
superTags = sTags;
}
});
this.tagService.getAllTagsByType('user').subscribe((tags) => {
if (tags) {
this.tagList = superTags.concat(tags);
}
this.loading = false;
});
search(value: string, tags?: string[]) {
if (!tags) {
tags = [];
}
this.loading = true;
this.chartSearchResults = [];
this.searchService.search(value, tags, 0, 50).subscribe((data) => {
if (data) {
this.filteredPubWorkSpaces = data.results;
for (let result of data.results) {
if (this.chartSearchResults.length < 10) this.chartSearchResults = this.chartSearchResults.concat(result.charts);
}
}
this.loading = false;
})
}
changeSelected(parameter: string, query: string) {
this.cdr.detectChanges();
const index = this.tagSearch.indexOf(query);
if (index >= 0) {
this.tagSearch.splice(index, 1);
}
else {
this.tagSearch.push(query);
}
this.search("", this.tagSearch);
}

发布于 2020-06-16 11:21:33
在这里它是不可见的,但是您的mc-workspace-card-list组件正在过滤显示(搜索)的药丸,或者您的searchService.search()方法正在过滤这些药片,我猜是后者。
您需要修改searchService.search()方法以返回workSpaces上完整的药丸列表。如果编辑和发布搜索方法,可能需要更改一两行。
https://stackoverflow.com/questions/62399742
复制相似问题