2016-09-12 8 views
0

良い日、EasySearchパッケージを使用した流星の簡単な検索機能

簡単検索パッケージを使用して簡単な検索機能を作成しようとしています。一言で言えば

私は、次のようなクライアント上のスキーマとインデックスを定義following-

行っている:

const Patients = new Mongo.Collection('patients'); 
 

 
const PatientsIndex = new EasySearch.Index({ 
 
    collection: Patients, 
 
    fields: ['name'], 
 
    engine: new EasySearch.MongoDB() 
 
    });
私はに次の値を入力した

データベース:

meteor:PRIMARY> db.patients.find() 
 
{ "_id" : ObjectId("57d6a9f71bad26ba07748f9d"), "name" : "Paul" }

Template.searchBox.helpers({ 
 
    patientsIndex:() => PatientsIndex 
 
});

そして最後に、私はテンプレートを出力すべき結果作成しました::

<template name="searchBox"> 
 
    {{> EasySearch.Input index=patientsIndex }} 
 
    <ul> 
 
     {{#EasySearch.Each index=patientsIndex }} 
 
      <li>Name of the patient: {{name}}</li> 
 
     {{/EasySearch.Each}} 
 
    </ul> 
 
</template>

は、クライアント側のテンプレートヘルパーを作成しました

何らかの理由でこれがうまくいかず、テンプレートに何も表示されません。これはとても新しいものであり、本当に助けに感謝します。

ありがとうございます。

答えて

0

コードサンプルからは、PatientsPatientsIndexの両方をグローバルに参照しようとしているようです。共有クライアント/サーバーの場所(/libなど)にPatientsPatientsIndexの宣言があると仮定すると、constというキーワードを削除する必要があります。これにより、これらの宣言がグローバルに利用できるようになり、テンプレートがそれらの宣言を使用できるようになります。ここでは動作しますあなたのコードの修正版です:

/lib/collection.js

Patients = new Mongo.Collection('patients'); 

PatientsIndex = new EasySearch.Index({ 
    collection: Patients, 
    fields: ['name'], 
    engine: new EasySearch.MongoDB() 
}); 

/client/main.html

<body> 
    {{> searchBox}} 
</body> 

<template name="searchBox"> 
    {{> EasySearch.Input index=patientsIndex }} 
    <ul> 
    {{#EasySearch.Each index=patientsIndex }} 
     <li>Name of the patient: {{name}}</li> 
    {{/EasySearch.Each}} 
    </ul> 
</template> 

/クライアント/メイン.js

import { Template } from 'meteor/templating'; 
import './main.html'; 

Template.searchBox.helpers({ 
    patientsIndex() { 
    return PatientsIndex; 
    } 
}); 
+0

ご協力いただきありがとうございます。私は今理解しており、完璧な意味合いがあり、うまく機能しています。興味のある問題として、結果をグリッドに戻すにはどうすればよいですか? – Jacques

関連する問題