如何在视图中显示Meteor.user()配置文件数据
我想这应该是一个基本问题,但我已经挣扎了太久。我对Meteor比较陌生 我已经查看了Meteor.user()的文档,并且可以看到如何将其他信息添加到user.profile中。即如何在视图中显示Meteor.user()配置文件数据,meteor,Meteor,我想这应该是一个基本问题,但我已经挣扎了太久。我对Meteor比较陌生 我已经查看了Meteor.user()的文档,并且可以看到如何将其他信息添加到user.profile中。即 //JS file Meteor.users.insert({ username: 'admin', profile: { first_name: 'Clark', last_name: 'Kent' }, }); 那么,如何
//JS file
Meteor.users.insert({
username: 'admin',
profile: {
first_name: 'Clark',
last_name: 'Kent'
},
});
那么,如何在视图样板中显示纵断面信息?我可以通过视图和web控制台(Meteor.user()
)访问用户对象,但无法访问对象详细信息
我最初的想法是,我可以在我的把手模板中加载以下内容,但它们不起作用:
// HTML view
{{Meteor.user().username}}
{{Meteor.user().profile.first_name}}
{{Meteor.user().profile.last_name}}
非常感谢您的帮助。在您的模板中,您需要使用
{{currentUser}
而不是{{Meteor.user()}
您的插入是正确的 但是要显示像名字这样的信息,您必须提供一个helper函数 您的html模板:
<template name="user">
<p>{{firstName}}</p>
</template>
{{#with currentUser}}
{{#with profile}}
{{first_name}}
{{/with}}
{{/with}}
您还可以使用{{currentUser}}帮助程序包装用户模板,以确保存在用户
{{#if currentUser}}
{{> user}}
{{/if}}
如果不想为嵌套在
{{currentUser}}
中的对象的不同属性定义代理帮助器,可以在模板中执行以下操作:
{{#with currentUser}}
{{#with profile}}
{{first_name}}
{{/with}}
{{/with}}
更新以反映评论建议。请尝试这种方式
{{#with userDetails}}
First name:-{{this.first_name}}
Last name:- {{this.last_name}}
{{/with}}
//jsSide
userDetails(){
return Meteor.user();
}
啊。很抱歉回复得太晚了。非常感谢。只要
{{currentUser.profile.first_name}}
就可以了。