这不是在我的模板中设置的?

时间:2014-06-13 09:35:52

标签: meteor iron-router

我有一个问题,看起来这个没有在我的模板中设置。这种情况以前没有发生过,我不知道发生了什么变化。

我的router.js

Router.map(function() {
  this.route('gameRoom', {
    path : '/game/:_id',
    controller : GameRoomController
  });

控制器

GameRoomController = RouteController.extend({
  template : 'DetailsSubmit',

  waitOn : function() {
    return [
      Meteor.subscribe('gameList', this.params._id),
      Meteor.subscribe('gameInfo', this.params._id),
      Meteor.subscribe('hintsList', this.params._id),
      Meteor.subscribe('guessList', this.params._id),
      Meteor.subscribe('imagesList', this.params._id),
      Meteor.subscribe('allUsers')
//            Meteor.subscribe('scoreList', this.params._id)
// stil in development will optimize this later
    ];
  },

  data : function() {
    return Games.findOne(this.params._id);
  }
});

所以在我的detailsubmit.html中,我有以下模板(snippit)

<template name='DetailsSubmit'> 
    {{#if isWaitingOnAction}}
        <div id="profileInfo">
            <img src="http://placehold.it/90x90" alt=""/>
        </div>
    {{/if}}
</template>

如果我输入Games.find()。fetch(),它将正确输出:

_id: "5DDCNfWiBeHG4o7nQ"
active: true
finished: false
players: Array[2]
round: 0
theBoss: "JLApNut5rTpRxoL9S"
thePlayer: "o5aJETfWQTjEkZprf"
__proto__: Object

因此,如果我尝试以下命令之一,我希望我的模板能正常工作:

我的助手:

Template.DetailsSubmit.helpers({

 isWaitingOnAction: function() {
        console.log(this) // return Object {} 
        console.log(Games.findOne(this._id)) // returns undefined in console
        console.log(Meteor.userId()); // returns correct userId 

    }
})

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

替换:

return Games.findOne(this.params._id);

使用:

return Games.findOne({_id:this.params._id});
相关问题