如果结果中有一个单词与我在数组中寻找的单词匹配,我该如何显示彩色?
例如,我正在搜索“测试”,在结果中“这是一个测试”,如果它写入我需要在此结果中为测试文本的背景上色,
这是我的代码;
this.searchControl.valueChanges
.pipe(
distinctUntilChanged()
)
.subscribe((query: string) => {
this.filteredSubtitles = []
this.docViewerServiceService.getSubTitles
.map(o => o.subTitle)
.forEach(o => {
//searching part
const filtered = o.filter(subtitle => subtitle.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase()))
this.filteredSubtitles.push([...filtered]);
//Matching part of the searched word with the word in the string
this.filteredSubtitles.find(o => {
if (o.filter(a => a.includes(query))) {
yes i'm stuck here there is no need for this if maybe but i don't know
}
});
})
//as a whole to divide the words in the string we get and the time range into strings.
this.filteredSubtitles.forEach(findedSubTitles => this.pushFindedTitles = findedSubTitles)
})}
for example i am searching "TEST" and in the results "THIS IS A TEST" if it writes i need to color the background of TEST text in this result
here is my code;
this.searchControl.valueChanges
.pipe(
distinctUntilChanged()
)
.subscribe((query: string) => {
this.filteredSubtitles = []
this.docViewerServiceService.getSubTitles
.map(o => o.subTitle)
.forEach(o => {
//searching part
const filtered = o.filter(subtitle => subtitle.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase()))
this.filteredSubtitles.push([...filtered]);
//Matching part of the searched word with the word in the string
this.filteredSubtitles.find(o => {
if (o.filter(a => a.includes(query))) {
yes i'm stuck here there is no need for this if maybe but i don't know
}
});
})
//as a whole to divide the words in the string we get and the time range into strings.
this.filteredSubtitles.forEach(findedSubTitles => this.pushFindedTitles = findedSubTitles)
})}
my purpose here is if there is "LEKE" in the Array, enclose it in span tags and change its background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在循环模板上,所有匹配都将在跨度标签内
on your template for loop, all the matches will be inside a span tag