2017-05-08 9 views
0

にページごとのヒット数を設定する方法:<a href="https://github.com/algolia/autocomplete.js#hits" rel="nofollow noreferrer">it states</a>オートコンプリートのドキュメントでは、Algoliaのオートコンプリート

Hits

To build a source based on Algolia's hits array, just use:

{ 
    source: autocomplete.sources.hits(indexObj, { hitsPerPage: 2 }), 
    templates: { 
    suggestion: function(suggestion, answer) { 
     // FIXME 
    } 
    } 
} 

をしかし、私はidexObjをすることになっているかわからないんだけど。私は3つのインデックスとinstantsearchのインスタンスを持っていますが、どちらかの指標を渡すと、次のエラー得られますでindexObj結果を渡しながら

autocomplete.min.js?_=1494237458641:7 Uncaught TypeError: Cannot read property '_ua' of undefined 

を:私は結果の数を制限する必要が

Uncaught ReferenceError: indexObj is not defined 

示し、Iソースを渡す必要がありますが、私はそれを渡す方法を把握することはできません。

+1

次の例に示すように、インデックスを生成する必要があります。https://github.com/algolia/autocomplete.js#standalone – rishipuri

答えて

0

@rishipuriは正しくありましたが、複数のインデックスを使用しているため、この例は実際にはカウントされませんでした。しかし、それは私が次見つけた私はthe documentationに戻るになりました:

autocomplete('#aa-search-input', {}, [ 
    { 
     source: autocomplete.sources.hits(players, { hitsPerPage: 3 }), 
     displayKey: 'name', 
     templates: { 
     header: '<div class="aa-suggestions-category">Players</div>', 
     suggestion: function(suggestion) { 
      return '<span>' + 
      suggestion._highlightResult.name.value + '</span><span>' 
       + suggestion._highlightResult.team.value + '</span>'; 
     } 
     } 
    }, 
    { 
     source: autocomplete.sources.hits(teams, { hitsPerPage: 3 }), 
     displayKey: 'name', 
     templates: { 
     header: '<div class="aa-suggestions-category">Teams</div>', 
     suggestion: function(suggestion) { 
      return '<span>' + 
      suggestion._highlightResult.name.value + '</span><span>' 
       + suggestion._highlightResult.location.value + '</span>'; 
     } 
     } 
    } 
]); 

hitsPerPageは非常に便利です、ここでソース定義、で渡されます。

関連する問題

 関連する問題