2017-02-26 297 views
1

我使用的是阿爾戈利亞反應即時搜索,並且我有要求在每次有結果時顯示重疊。React即時搜索:onSearchStateChange獲取返回的匹配數

所以我想通過algolia提供的onSearchStateChange函數來處理它。但我仍然困惑從哪裏獲得總點擊。我已經有了一個想法,就像使用通過jquery提取數字顯示的結果一樣。但我不想這樣做。有沒有其他方式可以建議?

onSearchStateChange(nextState) { 

    //must get the number of total hits. 

    nextState = cleanDeep(nextState); 
    let filters = transformer(nextState); 
    this.setState({ 
     searchState: nextState, 
     filters: filters, 
     searchChanged: true 
    }) 
    this.sendToAti(filters); 

    this.addOverlay(); // <--- function that will show the overlay. 

    location.hash = qs.stringify(nextState); 
} 

回答

3

onSearchStateChange功能不包含searchResults對象,你可以找到的點擊次數。

但是,我們提供了一個<Stats>小部件和一個connectStats連接器,其中包含此信息。也許你可以使用它?