2016-10-06 7 views
0

私は、ソートを実装し、私のアイテムを検索しようとしているので、私はソートで開始し、それが動作します:検索やソート、同じページ上

テンプレート

<button class="sort">Sort</button> 

     {{#each cvs}} 
       {{> Interviu}} 
     {{/each}} 

JS :私はIMPたかった

Template.Interviuri.onCreated(function() { 
     var self = this 
     self.autorun(function() { 
      self.sortOrder = new ReactiveVar(-1) 
     }) 

    Template.Interviuri.helpers({ 
     cvs() { 
      const instance = Template.instance() 
      return Cvs.find({}, { sort: { createdAt: instance.sortOrder.get() } }) 
     }, 
    }) 
    Template.Interviuri.events({ 
     'click .sort'(event, instance) { 
      instance.sortOrder.set(instance.sortOrder.get() * -1) 

次検索同じページにあります。だから私が見つけた最良の方法は、EasySearchでした。 しかし、EasySearchを使用すると、アイテムが表示される方法を変更する必要があることを意味します。そしてソートはもう動作しません。

テンプレート

<div class="searchBox pull-right"> 
     {{> EasySearch.Input index=cvsIndex attributes=searchAttributes }} 
    </div> 

     {{#EasySearch.Each index=cvsIndex }} 
      {{> Interviu}} 
     {{/EasySearch.Each}} 

コレクション

CvsIndex = new EasySearch.Index({ 
    collection: Cvs, 
    fields: ['name'], 
    engine: new EasySearch.Minimongo() 
}) 

JS

cvsIndex:() => CvsIndex, 

検索と並べ替えの両方を同時に行うことができますか?

答えて

0

EasySearchでは、インデックスに2つの方法、つまりgetComponentDict()getComponentMethods()を使用できます。あなたが検索定義とオプションにアクセスすることができますgetComponentDict()

index.getComponentDict().get('searchDefinition'); 
index.getComponentDict().get('searchOptions'); 

また、検索定義/オプションを変更するには、対応するセッターを持っています。

index = new EasySearch.index({ 
    // other parameters 
    engine: new EasySearch.MongoDB({ 
    sort: function(searchObject, options) { 
     if(options.search.props.sort) { 
     return parseInt(options.search.props.sort); 
     } 
     return 1; 
    } 
    }) 
}); 

getComponentMethodsは、あなたが、あなたの小道具を設定index.getComponentMethods().addProp('sort', -1)を言うと、インデックスの定義上、ごMongoDBのエンジンでは、その小道具からの並べ替えを設定することができることから、

index.getComponentMethods().loadMore(integer); 
index.getComponentMethods().hasMoreDocuments(); 
index.getComponentMethods().addProps(prop, value); 
index.getComponentMethods().removeProps([prop]) 

ようmehodsを持っています

詳細については、EasySearch Enginesを参照してください。

関連する問題