Javascript Meteor.user()错误:未捕获类型错误:无法读取属性';名称';空的
我正在使用Meteor框架,当我试图将当前用户的名称返回给模板助手时,出现了这个错误Javascript Meteor.user()错误:未捕获类型错误:无法读取属性';名称';空的,javascript,meteor,Javascript,Meteor,我正在使用Meteor框架,当我试图将当前用户的名称返回给模板助手时,出现了这个错误 Template.user.userName = function (){ return Meteor.user().name; } <template name ="user"> {{userName}} </template> Template.user.userName=函数(){ 返回Meteor.user().name; } {{userName}} 我
Template.user.userName = function (){
return Meteor.user().name;
}
<template name ="user">
{{userName}}
</template>
Template.user.userName=函数(){
返回Meteor.user().name;
}
{{userName}}
我一直收到此错误:(错误:未捕获的TypeError:无法读取null的属性“name”)
但是,在javascript控制台中,一切都可以正常工作
任何帮助都将不胜感激
Meteor.user()
如果没有用户登录,则返回null。为了安全起见,您应该执行类似于Meteor.user()的操作?Meteor.user().name:''
Meteor.user()
如果没有用户登录,则返回null。为了安全起见,您应该执行类似于Meteor.user()的操作?Meteor.user().name:''
什么是Meteor.user()?您是否检查过它以查看其值(可能为空)?它是Meteor提供的javascript对象。它返回[object object],但不带.name属性。console.log返回两行,null,然后依次返回对象。对象包含所有预期属性。Meteor.user()是什么?您是否检查过它以查看其值(可能为空)?它是Meteor提供的javascript对象。它返回[object object],但不带.name属性。console.log返回两行,null,然后依次返回对象。该对象包含所有预期属性。