根据Angular 14中的搜索结果扩展特定的垫子手风琴
我在手风琴上方搜索了一个单词选项,因此用户可以在手风琴中搜索特定的单词,并且那些具有匹配的单词的手风琴被扩展并突出显示了搜索的单词。目前,搜索并突出显示字符串部分正在工作,但是根据所选索引,手风琴并没有扩展。默认情况下,只有第一个手风琴才能为所有搜索结果打开。在此处输入图像描述 您能帮助以下代码中缺少的内容吗?
terms.ts
import { Component, OnInit } from '@angular/core';
import { CommonService } from '../service/common.service';
import { GlossaryOfTerms } from '../model/GlossaryOfTerms.model';
@Component({
selector: 'app-terms',
templateUrl: './terms.component.html',
styleUrls: ['./terms.component.scss']
})
export class GlossaryOfTermsComponent implements OnInit {
search: string = "";
gTerms: GlossaryOfTerms[] = [];
step = 0;
constructor(private commonService: CommonService) {}
ngOnInit(): void {
this.getTerms();
}
public OnSearched(searchTerm: string) {
this.search = searchTerm;
this.findSearchedValue();
}
getTerms(): void {
this.commonService.getGlossaryOfTerms().subscribe((terms) => {
this.gTerms = terms;
console.log("terms", this.gTerms );
});
}
findSearchedValue(): void {
this.gTerms?.forEach((terms, index) => {
var decription = terms.description;
var name = terms.name;
if(this.search != '' || undefined) {
if ((decription?.includes(this.search)) || (name?.includes( this.search) )) {
console.log("openindex", index);
this.step = index;
} else {
console.log("closeindex", index);
this.step = index;
}
}
});
}
}
<app-search #searchedValue (searched)="OnSearched($event)"></app-search>
<mat-accordion multi="true">
<mat-expansion-panel #accordianContainer *ngFor="let term of gTerms; let i = index" [expanded]="step === i">
<mat-expansion-panel-header>
<mat-panel-title>
<p [innerHTML]="term.name | highlightSearch: search"></p>
</mat-panel-title>
</mat-expansion-panel-header>
<div class="content">
<div class="content-text">
<p [innerHTML]="term.description | highlightSearch: search"></p>
</div>
</div>
</mat-expansion-panel>
</mat-accordion>
I have a search for a word option above the accordion, so users can search for a specific word in the accordion and those accordions that has the words matched are expanded and the searched word is highlighted. For now the search and highlight the string part is working, but the accordions doesn't expand per the indexes selected. Only the first accordion opens by default for all search result.enter image description here
Can you help with what i'm missing in the below code?
terms.ts
import { Component, OnInit } from '@angular/core';
import { CommonService } from '../service/common.service';
import { GlossaryOfTerms } from '../model/GlossaryOfTerms.model';
@Component({
selector: 'app-terms',
templateUrl: './terms.component.html',
styleUrls: ['./terms.component.scss']
})
export class GlossaryOfTermsComponent implements OnInit {
search: string = "";
gTerms: GlossaryOfTerms[] = [];
step = 0;
constructor(private commonService: CommonService) {}
ngOnInit(): void {
this.getTerms();
}
public OnSearched(searchTerm: string) {
this.search = searchTerm;
this.findSearchedValue();
}
getTerms(): void {
this.commonService.getGlossaryOfTerms().subscribe((terms) => {
this.gTerms = terms;
console.log("terms", this.gTerms );
});
}
findSearchedValue(): void {
this.gTerms?.forEach((terms, index) => {
var decription = terms.description;
var name = terms.name;
if(this.search != '' || undefined) {
if ((decription?.includes(this.search)) || (name?.includes( this.search) )) {
console.log("openindex", index);
this.step = index;
} else {
console.log("closeindex", index);
this.step = index;
}
}
});
}
}
<app-search #searchedValue (searched)="OnSearched($event)"></app-search>
<mat-accordion multi="true">
<mat-expansion-panel #accordianContainer *ngFor="let term of gTerms; let i = index" [expanded]="step === i">
<mat-expansion-panel-header>
<mat-panel-title>
<p [innerHTML]="term.name | highlightSearch: search"></p>
</mat-panel-title>
</mat-expansion-panel-header>
<div class="content">
<div class="content-text">
<p [innerHTML]="term.description | highlightSearch: search"></p>
</div>
</div>
</mat-expansion-panel>
</mat-accordion>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了我问题的解决方案,因为有人可以发现它有帮助。
打开选择
I found the solution to my question, as someone can find it helpful.
Open the select