相关疑难解决方法(0)

使用Iron Router进行waitOn订阅,该订阅依赖于来自其他订阅的文档的数据

我在配置waitOn路由的一部分时遇到问题,其中一个订阅的参数由来自不同订阅的文档中的值确定.

游戏中的收藏品是候选人和访谈.面试将只有一名候选人.这是一些示例数据:

candidate = {
    _id: 1
    firstName: 'Some',
    lastName: 'Developer'
    //other props
};

interview = { 
    _id: 1,
    candidateId: 1
    //other props
};
Run Code Online (Sandbox Code Playgroud)

路由配置如下.

this.route('conductInterview', {
    path: '/interviews/:_id/conduct', //:_id is the interviewId
    waitOn: function () {
        return [
            Meteor.subscribe('allUsers'),
            Meteor.subscribe('singleInterview', this.params._id),
            // don't know the candidateId to lookup because it's stored
            // in the interview doc
            Meteor.subscribe('singleCandidate', ???), 
            Meteor.subscribe('questions'),
            Meteor.subscribe('allUsers')
        ];
    },
    data: function () {
        var interview = Interviews.findOne(this.params._id);
        return {
            interview: interview,
            candidate: Candidates.findOne(interview.candidateId);
        }; …
Run Code Online (Sandbox Code Playgroud)

meteor iron-router

9
推荐指数
2
解决办法
1558
查看次数

根据另一个集合中特定文档的存在,将集合中的文档发布到流星客户端(发布与关系)

我有两个系列

  1. 优惠(相关领域:_ id)
  2. ShareRelations(相关领域:receiverIdofferId)

并且我只想向已登录用户发布已分享给他的优惠.

实际上,我是通过使用辅助数组(visibleOffers)来实现的,我通过循环为每个ShareRelations填充,然后在Offers.find上使用此数组作为$ in选择器.

我想知道这可能是这样做的流星方式,还是我可以用更少和/或更漂亮的代码?

我发布优惠的实际代码如下:

Meteor.publish('offersShared', function () {
  // check if the user is logged in
  if (this.userId) {
    // initialize helper array
    var visibleOffers = [];
    // initialize all shareRelations which the actual user is the receiver
    var shareRelations = ShareRelations.find({receiverId: this.userId});
    // check if such relations exist
    if (shareRelations.count()) {
      // loop trough all shareRelations and push the offerId to the array if the …
Run Code Online (Sandbox Code Playgroud)

publish meteor

8
推荐指数
1
解决办法
1777
查看次数

标签 统计

meteor ×2

iron-router ×1

publish ×1