meteor+coffeejs使用中遇到的坑(无法subscribe数据)

Meteor使用过程中publications中发布的集合count有数据,route中订阅后,client端没有返回结果,mongol查看到的集合为空,代码是这样写的:

 if !this.userId
    return cancel()
  else
    find: ->
      options = {doctorId: this.userId}
      if(patientId? and patientId )
        options.patientId = patientId
      if(event? and event )
        options.event = event
      console.log("options :: ",options)
      Osi.Collection.History.find options,{limit: 20}
      console.log "history count:: ",      Osi.Collection.History.find(options,{limit: 20}).count()

最后发现,find会把最后一行当作结果返回,呵呵呵,真相后顿时觉得一万只羊驼奔腾而过,花了两个小时踩过的坑,马克一下。
正确的写法是:

 if !this.userId
    return cancel()
  else
    find: ->
      options = {doctorId: this.userId}
      if(patientId? and patientId )
        options.patientId = patientId
      if(event? and event )
        options.event = event
      console.log("options :: ",options)
      console.log "history count:: ",    Osi.Collection.History.find(options,{limit: 20}).count()
      Osis.Collection.History.find options,{limit: 20}

如果要查看记录的条数,将count()放到上面,否则会把count挡住结果renturn回去。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章