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回去。

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