Javascript 数据不存在';不要在Meteor中正确加载
在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(
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中查看网络,看看网络上发生了什么。