Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数据不存在';不要在Meteor中正确加载_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript 数据不存在';不要在Meteor中正确加载

Javascript 数据不存在';不要在Meteor中正确加载,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,在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(

在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,如果你回击,数据就会加载得很好。有什么我做错了吗

  • waitOn
    订阅以确保在调用
    action
    之前数据准备就绪,并且在此之前显示
    loadingTemplate
  • 为了安全起见,永远不要从客户端向订阅或方法传递
    Meteor.userId()
    。只需在服务器端使用
    this.userId
    (发布函数)或
    Meteor.userId()
    (方法)

  • 您要求我们假设一个上下文,其中它始终是“未定义的内容以外的内容”
    data=UserInfoDB.find({userId:Meteor.userId()}).fetch()[0]
    ?是的,注册新帐户时会自动生成UserInfoDB条目。现在不会调用操作。新代码:另外,我对Meteor.userId()的代码编写得很差部分,我计划在网站上线之前修复它。你不应该再在
    操作中使用
    if(this.ready())
    。即使删除它,操作仍然不会被调用。我需要这样做吗。下一步()还是什么?你的出版物在服务器上准备好了吗?如果是这样,它应该可以工作。你可能想在inspector中查看网络,看看网络上发生了什么。