Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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.user()错误:未捕获类型错误:无法读取属性';名称';空的_Javascript_Meteor - Fatal编程技术网

Javascript Meteor.user()错误:未捕获类型错误:无法读取属性';名称';空的

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}} 我

我正在使用Meteor框架,当我试图将当前用户的名称返回给模板助手时,出现了这个错误

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,然后依次返回对象。该对象包含所有预期属性。