簡體   English   中英

數據無法在Meteor中正確加載

[英]Data doesn't load properly in Meteor

在流星中,當我的頁面加載數據時,我的常規設置是:

var data

Router.route('/userinfo/edit', {
  loadingTemplate: 'Loading',
  subscriptions: function(){
    console.log('And now we wait')
    return Meteor.subscribe('_userinfodb', Meteor.userId())
  },
  action: function(){
    console.log('RonPaulItsHappening.gif')
    data = UserInfoDB.find({userId: Meteor.userId()}).fetch()[0]
    if(typeof data == "undefined"){
      var errorReport = 'User ' + Meteor.userId() + ' failed to retrive data from UserInfoDB, on page ' + Router.current().path + ' on ' + new Date() + '.'
      Meteor.call('generateErrorReport', errorReport)
      this.redirect('/error/data')
    }
    console.log(data)
    this.render('userinfoedit')
  }
})

這偶爾會起作用,但相當復雜,通常會導致數據未定義。 但是,如果您回擊了/ error / data,則數據加載就可以了。 我做錯什么了嗎?

  1. waitOn訂閱,以確保在調用action之前數據已准備就緒,並在此loadingTemplate顯示loadingTemplate
  2. 為了安全起見,永遠不要將Meteor.userId()從客戶端傳遞給訂閱或方法。 只需在服務器端使用this.userId (發布函數)或Meteor.userId() (方法)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM