- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在标题中有一个输入搜索字段(粘性标题或在 css 世界中固定的位置),它允许获取记录列表,当您单击其中一个时,它会转到概览页面。当您在 keyup 上键入搜索词时,它会从 api 获取结果。它有 debounceTime 用于减少对 api 的请求。搜索结果是一个记录列表,但我遇到的问题是搜索在概览页面上不起作用。我需要做什么才能在概览页面上进行搜索?
这是搜索输入框:
<input #searchText [(ngModel)]="searchFilterText" id="m_quicksearch_input_disabled" autocomplete="off" type="text" name="searchFilterText" class="m-list-search__form-input" value="" placeholder="Search...">
这是在 header 组件中耗时跨度后得到处理的搜索函数:
processSearchTerm() {
if (this.searchTextRef) {
fromEvent(this.searchTextRef.nativeElement, 'keyup')
.pipe(
debounceTime(AppConsts.DEBOUNCE_TIME),
distinctUntilChanged()
).subscribe(
value => this.getMyData(this.searchTextRef.nativeElement.value.trim())
);
}
}
下面是在header组件中获取搜索结果列表的代码:
getMyData(searchTerm: string): void {
if (searchTerm) {
this.initSpinner = true;
this._myDataServiceProxy.getmyDatasorSearchResults(
searchTerm
).subscribe(result => {
this.myDataRecords = result.items;
this.myDataRecordTotal = result.totalCount;
this.initSpinner = false;
});
} else {
this.myDataRecordTotal = AppConsts.RESET_MYDATA_RECORD_COUNT;
}
}
获取header组件中数据的详细信息:
goToMyDataOverview(id: number): void {
if (id) {
this._router.navigate([`/app/main/data/${id}`]);
}
}
带有标题组件中列表项的 anchor 标记:
<a (click)="goToMyDataOverview(item.id)"
href="javascript:;"
class="m-list-search__result-item"
*ngFor="let item of myDataRecords; let i = index;">
<span class="m-list-search__result-item-pic"><img class="m--img-rounded" src="assets/common/images/default-profile-picture.png" title="" alt="Profile picture"></span>
<span class="m-list-search__result-item-text">{{item.firstname}} {{item.lastname}}</span>
</a>
这里是概览组件的代码:
ngOnInit(): void {
const id = this.route.snapshot.paramMap.get('id');
if (id) {
this.getData(id);
}
}
getData(id: string): any {
if (id) {
this.initSpinner = true;
this._dataServiceProxy.getDataInformationById(
id
).subscribe(result => {
this.myData = result.data;
});
}
}
最佳答案
这里有相当多的代码......但从顶部开始:
如果这是模板:
<input #searchText
[(ngModel)]="searchFilterText"
id="m_quicksearch_input_disabled"
autocomplete="off"
type="text" name="searchFilterText"
class="m-list-search__form-input"
value="" placeholder="Search...">
这是关联的组件:
processSearchTerm() {
if (this.searchTextRef) {
fromEvent(this.searchTextRef.nativeElement, 'keyup')
.pipe(
debounceTime(AppConsts.DEBOUNCE_TIME),
distinctUntilChanged()
).subscribe(
value => this.getMyData(this.searchTextRef.nativeElement.value.trim())
);
}
}
那你就不需要用this.searchTextRef.nativeElement.value
了及其所有潜在问题。您在元素中使用双向绑定(bind) [(ngModel)]
所以你可以访问绑定(bind)属性:searchFilterText
.
但更好的解决方案(允许使用 debounceTime
的解决方案)是使用响应式(Reactive)形式:
模板:
<input [formControl]="searchTerm"
id="m_quicksearch_input_disabled"
autocomplete="off"
type="text" name="searchFilterText"
class="m-list-search__form-input"
value="" placeholder="Search...">
注意绑定(bind)到 formControl
,这是一个响应式表单指令。
组件:
searchTerm = new FormControl();
this.searchTerm.valueChanges
.pipe(
debounceTime(AppConsts.DEBOUNCE_TIME),
distinctUntilChanged()
).subscribe(
value => this.getMyData(value.trim())
)
因为它使用响应式形式,所以它有一个内置的 valueChanges
可观察到您可以观察变化。
看来 getMyData
也是此 header 组件的本地。因此只有 header 可以访问过滤后的数据。所以你的标题组件也会显示列表。然后链接到详细信息页面。
看起来详情(概览)页面随后再次获取数据,但这次只是针对单个项目。
但是现在您想在详细信息(概览)页面中使用相同 搜索功能吗?在这种情况下,您要搜索什么?
如果如您的问题标题所述,您希望搜索出现在所有页面上,您有以下几种选择:
1) 您可以将搜索 UI 构建为一个单独的组件,您可以使用 <searchForm></searchForm>
等标签将其放在任何页面上.由于 searchForm 元素将出现在每个页面上,您可以通过 @ViewChild
与它通信
2) 您可以像这样在顶部和底部构建带有搜索 UI 的页面:
<searchForm></searchForm>
<router-outlet></router-outlet>
您可以使用向任何需要它的组件提供 searchTerm 的服务。
我这里有最后一个选项的简化版本:https://stackblitz.com/edit/angular-simpleservice2-deborahk
它在顶部有一个搜索组件,下面有两个“选项卡”,提供对这两个页面的访问。它使用一项服务在页面之间共享搜索词。
关于angular - 如何使用 typescript 修复 Angular 5 中所有页面的 'search input field in the header',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54775882/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
在 Vim 中,我可以:set wrapscan,这样当我进行增量搜索时,无论第一个匹配项位于光标上方还是下方,光标都会跳转到第一个匹配项。 在 Emacs 中,如果我通过 C-s 开始搜索,如果第一
Elasticsearch 中的页面排名是如何工作的。一旦我们创建了一个索引,就会有一个底层智能层创建一个元数据存储库并提供结果以根据相关性进行查询。我已经创建了几个索引,我想知道在提供查询后结果是如
我们在单个节点上使用 Elasticsearch 对数据进行了索引。我们在后台运行了一个线程,用于使用最近的更改更新索引。 现在我们使用 Elasticsearch API 来运行搜索查询。 {
这突然停止工作,正在工作,但现在却没有: 如果我使用Twitter UI并转到: https://twitter.com/#!/search/%22social%20snap%22%20OR%20%
我在基类中声明了某些字段,并且我想仅为某些子类(实体)注册这些字段。 因此,我不想通过 @Field 注释基类中的这些字段,尽管只需以编程方式注册某些实体就足够了。 但是在基本实体中声明的字段未注册/
我的全文搜索索引有问题。我有一个字符字段大小为 30 的表。我在这个字段上创建了一个全文搜索索引,以便在这个不区分大小写的字段上进行快速搜索操作。现在,当我执行以下查询时:SELECT fieldna
我对SandCaSTLe的输出感到非常满意,但我也想在HTML输出中包含一些搜索功能,这可能吗? 最佳答案 SandCaSTLe帮助文件生成器的网站输出包含 index.aspx 和 index.ht
有没有人遇到过Apache Lucene的功能?我听说它甚至可以与Google Search Appliance(GSA)相提并论。我正在寻找两者之间的明确比较,如果可能的话? 在线上进行的比较非常模
在构建应用程序时,“查找”与“搜索”之间有什么有意义的区别吗?您是否将它们视为同义词? 我在询问应用程序UI和API设计的标签方面。 最佳答案 查找是搜索的完成。 如果您可能无法成功找到某些东西,则将
我想编写一个移动应用程序,它可以拍照并在谷歌图像中搜索类似的图片,然后显示结果。 但是,使用谷歌图像搜索我只能搜索文本字符串,而使用搜索 API 似乎无法搜索相似图片;此功能似乎只能通过网络界面使用。
当我从 Many2one 列表框中选择一个项目时,我想要进行高级搜索。例如,此功能是针对“res.groups”对象实现的。我在/addons 中找不到此功能。 更准确地说,我定义了我的对象 clas
我正在使用 Amazon CloudSearch 存储大量地点。每个地方在一周中的每一天都有开放时间和关闭时间。 我需要按当前时间检索地点。您如何建议对索引进行建模?我想通过创建 7 个文本索引来解决
我见过一些网站,当您执行搜索时会列出相关搜索,即它们会建议您可能感兴趣的其他搜索查询。 我想知道在中型网站中对此进行建模的最佳方法(没有足够的流量来依赖访问者统计数据来推断关系)。我最初的想法是存储每
如何从 Sitecore Lucene 搜索中获取格式化的 url?我创建了一个自定义索引,并在根目录下将其更新为/sitecore/content/websitename/home。 检索到搜索结果
我一直在努力寻找这个并且无法找到我想要的东西。 在我的状态行上,我想要计算当前文件中出现的匹配数。下面的 vim 命令返回我想要的。我需要返回的号码显示在我的状态行中。 :%s/^I^I//n vim
我们有自己的服务器与应用程序一起工作。我们开始使用不同的提供商进行托管,现在我们遇到了上述错误。 关于 同 页面,这有效: 但是这个不 我们无法弄清楚为什么会这样。您
题目地址:https://leetcode.com/problems/search-in-a-binary-search-tree/description/ 题目描述 Given the root
我正在使用很棒的插件 Leaflet.Control.Search为了在我的 map 上搜索标记(来自 geoJson 标记组)——效果很好。 我现在只有一个简单的问题:如何打开搜索结果标记的弹出窗口
我开发了一个允许创建新记录的扩展。 在列表模块中,在记录列表下,有搜索表单。 例如,它适用于 fe 用户,但不适用于我的自定义记录。 是否必须在我的 tca 中添加任何特殊配置才能使此表单与我的自定义
我是一名优秀的程序员,十分优秀!