如何控制两个订阅显示在一个模板中? [英] How do I control two subscriptions to display within a single template?

查看:30
本文介绍了如何控制两个订阅显示在一个模板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,对 Meteor 框架有点陌生!

Sorry kind of new to the Meteor framework!

我订阅了两个发布功能.即使两个发布函数都针对同一个集合,但它们都有不同的函数,我想在一个模板中显示这些函数.我如何实现这一目标.我已经做了大量的研究,但似乎没有足够的信息来说明如何实现.

I Subscribed to two Publish functions. Even if both publish functions target the same Collection, they both have different functions, that I would like to display in one template. How do I achieve this. I have done allot of research but there doesn't seem to be sufficient information on how to achieve.

以下是我订阅的代码中的两个发布函数:

Following are the two publish functions in code that I subscribe to:

.server/main.js:

.server/main.js:

Meteor.publish('MerchantTrending', function (categoryMan){
var currentUser = this.userId;

return buyList.find({ who:"Merchant", ownerId:currentUser, itemCategory: { $in: categoryMan } }, {skip: 0, limit: 3});

});

.server/main.js:

.server/main.js:

Meteor.publish('myTopViews', function (){

var currentUser = this.userId;
return buyList.find({ newArrivalsExpiryDate : {'$lte': new Date()}}, {ownerId:currentUser }, {skip: 0, limit: 3});
});

以下是代码中的订阅功能

Following is the subscription function in code

.client/main.js:

.client/main.js:

Router.route('/MerchantLandingPage', {    
subscriptions: function(){
      var categoryMan = Session.get('category');

    return  Meteor.subscribe('MerchantTrending', categoryMan, 'merchantTopViews')

}
});

现在代码中的辅助函数:

Now the helper function in code:

Template.MerchantLandingPage.helpers({

  'top3Trending' : function () {    
    return buyList.find({}).fetch();
    },

 'myTopViews' : function () {

    return buyList.find({}).fetch();
    }
});    

现在是代码中的模板:

<template name="MerchantLandingPage">

##### *** Top three trending items *** ########

{{#each top3Trending}}

ItemName::  <b>{{itemName}}</b> <br>
Item Category:: <b>{{itemCategory}}</b> <br>                 
Discription:: <b>{{descriptions}}</b> <br>  
Image:: {{this.photo._id}} <br> 
Date Created:: {{createdDate}} <br>  

{{/each}}

<br><br>

 ############ *** My top Views *** #############

{{#each myTopViews}}

ItemName::  <b>{{itemName}}</b> <br>
Item Category:: <b>{{itemCategory}}</b> <br>                 
Discription:: <b>{{descriptions}}</b> <br>  
Image:: {{this.photo._id}} <br> 
Date Created:: {{createdDate}} <br>   

{{/each}}

</template>

{{#each myTopViews}} 和 {{#each top3Trending}} 均成功显示但未正确显示.当

Both {{#each myTopViews}} and {{#each top3Trending}} successfully display but not correctly. When the variable categoryMan in

Meteor.subscribe('MerchantTrending', categoryMan, 'merchantTopViews')

Meteor.subscribe('MerchantTrending', categoryMan, 'merchantTopViews')

改变值,它同时影响 {{#each myTopViews}}{{#each top3Trending}} 的结果,当它只应该影响{{#each top3Trending}}.

changes value, it affects both both the outcome of both {{#each myTopViews}} and {{#each top3Trending}}, when its only supposed to affect {{#each top3Trending}}.

如何让订阅不影响 {{#each myTopViews}}{{#each top3Trending}},但只影响 {{#each myTopViews}} 在我的模板中?

How can I get the subscriptions to NOT have an affect on both {{#each myTopViews}} and {{#each top3Trending}}, but only {{#each myTopViews}} in my template?

感谢您的帮助!

推荐答案

有一个包 percolate:find-from-publication 允许过滤出版物中的数据.

There is a package percolate:find-from-publication that permits to filter the data from publications.

这篇关于如何控制两个订阅显示在一个模板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆