angular - 如何在角度 algolia 即时搜索中动态更改搜索参数
问题描述
我正在使用,并根据用户的输入<ais-configure [searchParameters]="{ aroundLatLng: '0, 0' }"></ais-configure>
动态更新对象,但我看不到搜索结果的任何变化。{ aroundLatLng: '23, 90' }
这是一个例子,我在codesandbox中准备 - https://codesandbox.io/s/kxqxr0j45r
在这个例子中,你可以看到最初,我添加了以下搜索参数:
searchParameters = { hitsPerPage: 3 };
还有一个名为“更新搜索参数”的按钮,当您单击该按钮时,它会更改搜索参数,例如 -
updateParameter() { this.searchParameters.hitsPerPage = 10; }
我期望对 searchParameters 的任何更改都应反映在搜索结果中。据此,我应该每页看到 10 个结果。但它不起作用。
你能告诉我我怎样才能做到这一点吗?谢谢。
解决方案
我认为您需要触发搜索。您是否尝试过完成本教程,其中显示:
“将 InstantSearch.js 安装到应用程序的依赖项后,我们需要将 InstantSearch.js 库实例化为 Angular 服务。”
然后您可以利用 AppComponent 中的即时搜索服务:
...
import { InstantSearchService } from './services/instantsearch.service';
...
export class AppComponent {
...
updateParameter() {
...
this.instantSearchService.search.start(); // trigger the search
}
}
推荐阅读
- java - .substring() 抛出一个 nullPointerException
- sql - script sh linux SQL过程执行
- three.js - 在 THREE.js 中将多种材质映射到 OBJ 模型
- python-3.x - NameError:名称“合并列表”未定义
- c# - 使用 ClosedXML 创建数据透视表
- flowtype - 将未定义的属性访问变成错误
- react-native - 首先反应原生应用,绕过应用商店?
- graphql - 使用来自 apollo-link-ws 的 WebSocketLinks 时添加 Graph*I*QL 订阅端点?
- javascript - 带有 forEach 循环的异步等待仍在异步运行
- multidimensional-array - BQ 数组查找:类似于 NTH,但基于索引,而不是位置