Meteor订阅所有页面

时间:2015-12-04 14:23:09

标签: meteor

当我在页面中搜索mongodb时,结果显示在我网站的所有页面中,即在页面上搜索" search1",我得到一个结果。当我进入页面" search2"时,我得到了" search1"在那里。我想从过去的结果中清除所有页面。这是一个例子:

meteorpad - bequipamentos

1 个答案:

答案 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');