【问题标题】:How to dynamically change search parameter in angular algolia instant search如何在角度 algolia 即时搜索中动态更改搜索参数
【发布时间】:2018-08-13 07:18:07
【问题描述】:

我正在使用<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 个结果。但它不起作用。

您能告诉我如何实现这一目标吗?谢谢。

【问题讨论】:

    标签: angular algolia instantsearch


    【解决方案1】:

    我认为您需要触发搜索。您是否尝试过完成this tutorial 上面写的:

    “将 InstantSearch.js 安装到应用程序的依赖项后,我们需要将 InstantSearch.js 库实例化为 Angular 服务。”

    然后您可以在 AppComponent 中利用 Instantsearch 服务:

    ...
    import { InstantSearchService } from './services/instantsearch.service';
    ...
    export class AppComponent {
    ...
        updateParameter() {
            ...
            this.instantSearchService.search.start(); // trigger the search
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2018-07-30
      • 2018-12-04
      • 2016-05-27
      相关资源
      最近更新 更多