我有一个集合,其中包含一个名为“类别”的项目列表,每个类别都有一个 _id 和一个名称字段。我试图简单地返回对类别名称的搜索
这是文档结构。每个列表项都有这些属性。我试图定位“名称”字段,但出现错误
I20160704-22:47:42.976(1)?调用方法“findCategory”ReferenceError 时出现异常:未定义 ID
客户端/html
<form class="form-inline">
<input type="text" class="form-control" id="searchCategory" placeholder="Search for Category">
<button type="submit" class="btn btn-info">Search</button>
</form>
{{#if foundCategory}}
<div class="foundCategory">
<button type="button" class="btn btn-default" id="follow">Follow @{{foundCategory.name}}</button>
</div>
{{/if}}
</template>
服务器/js
Meteor.methods({
'findCategory': function(name) {
return Meteor.CategoryCollection.findOne({
_id: id
}, {
fields: { 'name': 1 }
});
}
});
我试过了
Meteor.methods({
'findCategory': function(name) {
return CategoryCollection.findOne({
name : name
}, {
fields: { 'name': 1 }
});
}
});
但我得到了错误。
调用方法“findCategory”类型错误时出现异常:无法调用未定义的方法“findOne”
我怎样才能退回我需要的文件?
编辑
我使用rest2ddp调用 json 数据并将其插入到 CategoryCollection
我还将 Meteor.CategoryCollection 更改为简单的 CategoryCollection
服务器/main.js
REST2DDP.publish("CategoryPublication", {
collectionName: "CategoryCollection",
restUrl: "http://localhost:8888/wordpress/wp-json/wp/v2/categories",
jsonPath: "$.*",
pollInterval: 5000,
});
client.subscriptions.js
CategoryCollection = new Mongo.Collection("CategoryCollection");
Meteor.subscribe("CategoryPublication");
Tracker.autorun(function () {
console.log(CategoryCollection.find().fetch());
});