使用 EasySearch 包在meteor 中进行简单的搜索功能 [英] Simple search function in meteor using EasySearch package
问题描述
美好的一天,
我正在尝试使用简单搜索包创建一个简单的搜索功能.
I'm trying to create a simple search function using the easy search package.
简而言之,我做了以下-
In a nutshell I have done the following-
在客户端上定义架构和索引,如下所示:
Defined a schema and index on the client as such:
const Patients = new Mongo.Collection('patients');
const PatientsIndex = new EasySearch.Index({
collection: Patients,
fields: ['name'],
engine: new EasySearch.MongoDB()
});
我已将以下值输入到数据库中:
I've entered the following values into the database:
meteor:PRIMARY> db.patients.find()
{ "_id" : ObjectId("57d6a9f71bad26ba07748f9d"), "name" : "Paul" }
在客户端创建了一个模板助手:
Created a template helper on the client side:
Template.searchBox.helpers({
patientsIndex: () => PatientsIndex
});
最后我创建了一个模板来输出结果:
And lastly I've created a template which should output the results:
<template name="searchBox">
{{> EasySearch.Input index=patientsIndex }}
<ul>
{{#EasySearch.Each index=patientsIndex }}
<li>Name of the patient: {{name}}</li>
{{/EasySearch.Each}}
</ul>
</template>
现在由于某种原因这行不通,它对模板没有任何影响,我对此很陌生,非常感谢您的帮助.
Now for some reason this just wont work, it renders nothing to the template, I' very new to this and would really appreciate some assistance.
谢谢.
推荐答案
从您的代码示例看来,您正在尝试全局引用 Patients
和 PatientsIndex
.假设您在共享客户端/服务器位置(如 /lib
)中有 Patients
和 PatientsIndex
声明,那么您应该删除 const
关键字.这将确保这些声明在全球范围内可用,并允许您的模板使用它们.这是您的代码的修改版本,可以正常工作:
From your code samples it looks like you're trying to refer to both Patients
and PatientsIndex
globally. Assuming you have your Patients
and PatientsIndex
declarations in a shared client/server location (like /lib
), then you should remove the const
keyword. That will make sure these declarations are available globally, and will allow your Template to use them. Here's a modified version of your code that will work:
/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>
/client/main.js
import { Template } from 'meteor/templating';
import './main.html';
Template.searchBox.helpers({
patientsIndex() {
return PatientsIndex;
}
});
这篇关于使用 EasySearch 包在meteor 中进行简单的搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!