"Match.Error"消息 : "Match error: Expected particular constructor"



我是 Meteor 和 React 框架的新手,并且 我正在尝试将"搜索"合并到流星中,并使用软件包轻松搜索。我收到错误。错误的确切措辞如下:

match.js:40 Uncaught 
errorClass {message: "Match error: Expected particular constructor", path: "", sanitizedError: errorClass, errorType: "Match.Error", stack: "Error: Match error: Expected particular constructo…5a95662d577f9e8a17248e5683161da2f8b114da:3779:14)"}
errorType: "Match.Error"
message: "Match error: Expected particular constructor"
path: ""

我真的不明白为什么会发生此错误以及如何解决这个问题。我正在下面编写我的代码,以便可以准确地找到错误。

搜索.html(用于搜索的 Blaze 模板(

<template name="search">
<div id="search-wrap">
<div>Search page!</div>
<div class="black searchbar">
{{> EasySearch.Input index=index attributes=inputAttributes }}
</div>
{{#EasySearch.IfInputEmpty index=index }}
<div class="padded examples black">For example "Company 1"</div>
{{else}}
{{#if resultsCount}}
<div class="padded count-results black">{{resultsCount}} results found.</div>
{{/if}}
{{/EasySearch.IfInputEmpty}}
{{#EasySearch.IfSearching index=index }}
<div>Searching</div>
{{/EasySearch.IfSearching}}
<ol class="leaderboard">
{{#EasySearch.Each index=index }}
{{> User}}
{{/EasySearch.Each}}
</ol>
{{#EasySearch.IfNoResults index=index }}
<div class="padded no-results black">No results found</div>
{{else}}
{{/EasySearch.IfNoResults}}
{{> EasySearch.Pagination index=index maxPages=10 }}
{{! > EasySearch.LoadMore index=index}}
{{#if showMore}}
{{> EasySearch.Input name="mini-index" index=index attributes=inputAttributes }}
<ul>
{{#EasySearch.Each name="mini-index" index=index}}
<li>{{name}}</li>
{{/EasySearch.Each}}
</ul>
{{/if}}
<!-- Easy Search -->
</div>
<!-- End search -->
--></template>
<template name="User">
<li class="user black {{selected}}" id="user-link">
<span class="name">{{name}}</span>
</li>
</template>

索引.js文件(在集合上创建索引 - 公司(

import Companies from "./companies.js";
import { EasySearch } from 'meteor/easy:search';
import { Meteor } from 'meteor/meteor';
import { Mongo } from "meteor/mongo";

export const CompaniesIndex = new EasySearch.Index({
engine: new EasySearch.MongoDB({
sort: function() {
//return based on the latest additions, newest on top
return { createdAt: -1 };
},
//something easy search always asks for
selector: function(searchObject, options, aggregation) {
let selector = this.defaultConfiguration().selector(searchObject, options, aggregation),
//to sort with category.
categoryFilter = options.search.props.categoryFilter;
//search with a category, not really sure what it does, using the easysearch docs.
if(_.isString(categoryFilter) && !_.isEmpty(categoryFilter)) {
selector.category = categoryFilter;
}
return selector;
}
}),
//collection name
collection: Companies,
//fieldname to be searched on
fields: ['name'],
defaultSearchOptions: {
//limit the results size to be 10
limit: 10
},
permission: () => {
return true;
}
});
// export const CompaniesIndex;

jsx 文件 (Company-search-trial.jsx(

import React from "react";
import Blaze from "meteor/gadicc:blaze-react-component";
import "./pages/search.html";
import Companies from "../api/data/companies.js";
import CompaniesIndex from "../api/data/index.js";
/* A set of controls for the user to select search queries and options.
* For use in the CompanySearchPage.
*/

Template.search.rendered = function() {
$("#search-link").addClass('selected');
$("#profile-link").removeClass('selected');
$("#rankings-link").removeClass('selected');
$("#jokes-link").removeClass('selected');
$("#login-link").removeClass('selected');
}
Template.search.helpers({
inputAttributes: function() {
return { 'class': 'easy-search-input', 'placeholder': 'Start Searching' };
},
players: function() {
return Companies.find({}, { sort: { createdAt: -1 } });
},
selectedName: function() {
var company = CompaniesIndex.config.mongoCollection.findOne({ __originalId: Session.get("selectedCompany") });
return company && company.Name;
},
index: function () {
return CompaniesIndex;
},
resultsCount: function() {
return CompaniesIndex.getComponentDict().get('count');
},
showMore: function() {
return false;
},
renderTmpl: () => Template.renderTemplate
});
Template.User.helpers({
selected: function() {
return Session.equals("selectedCompany", this.__originalId) ? "selected" : '';
},
});
Template.User.events({
'click': function() {
Session.set("selectedCompany", this.__originalId);
}
});

export default class CompanySearchTrial extends React.Component {
render() {
return (
<div className="page CompanySearchTrial">
<Blaze template="search"/>
</div>
);
}
}

有人可以帮我解决这个问题吗?我真的不知道该怎么做。谢谢!

错误:Match error: Expected particular constructor"指向函数参数无效的可能原因。它还为我们提供了指针,表明这是一个缺少的构造函数,这是问题所在。

代码中使用构造函数的两件事(即用new实例化(是EasySearch.IndexEasySearch.MongoDBEngine

快速浏览一下 EasySearch 的文档,导入这两个类的正确方法是这样的:

import { Index, MongoDBEngine } from 'meteor/easy:search'
// Client and Server
const index = new Index({
...
engine: new MongoDBEngine({
sort: () => { score: 1 },
}),
});

试一试以上内容,看看它是否解决了您的问题

最新更新