当我在页面中搜索mongodb时,结果显示在我网站的所有页面中,即在页面上搜索" search1",我得到一个结果。当我进入页面" search2"时,我得到了" search1"在那里。我想从过去的结果中清除所有页面。这是一个例子:
答案 0 :(得分:1)
<强> .meteor /包:强>
...
kadira:flow-router
kadira:blaze-layout
...
<强> searchName.html:强>
<template name="searchName">
<div class="Search">
{{#with result}}
<div>{{name}}</div>
{{/with}}
</div>
</template>
<强> searchName.js:强>
Template.searchName.helpers({
result: function () {
return Names.findOne();
}
});
<强> searchCode.html:强>
<template name="searchCode">
<div class="SearchCode">
{{#with result}}
<div>{{code}}</div>
{{/with}}
</div>
</template>
<强> searchCode.js:强>
Template.searchCode.helpers({
result: function () {
return Codes.findOne();
}
});
<强> router.js:强>
FlowRouter.route('/name/:query', {
subscriptions: function (params, queryParams) {
this.register('name', Meteor.subscribe('Name', params.query));
},
action: function () {
BlazeLayout.render('mainLayout', {
main: 'searchName'
});
},
name: 'searchName'
});
FlowRouter.route('/code/:query', {
subscriptions: function (params, queryParams) {
this.register('code', Meteor.subscribe('Code', params.query));
},
action: function () {
BlazeLayout.render('mainLayout', {
main: 'searchCode'
});
},
name: 'searchCode'
});
<强>的layout.html:强>
<template name="layout">
<div class="Layout">
{{> Template.dynamic template=main}}
</div>
</template>
服务器/ publications.js:强>
Meteor.publish('Names', function () {
return Names.find();
});
Meteor.publish('Name', function (_id) {
return Names.find({
_id: _id
});
});
Meteor.publish('Codes', function () {
return Codes.find();
});
Meteor.publish('Code', function (_id) {
return Codes.find({
_id: _id
});
});
<强> LIB / collections.js:强>
Names = new Mongo.Collection('names');
Codes= new Mongo.Collection('codes');