gpt4 book ai didi

meteor - 如何在 View 中显示 Meteor.user() 配置文件数据

转载 作者:行者123 更新时间:2023-12-03 15:08:04 24 4
gpt4 key购买 nike

我想这必须是一个基本问题,但是我已经为此苦苦挣扎了太久。我对 Meteor 比较陌生。

我已经查看了 Meteor.user() ( http://docs.meteor.com/#meteor_users ) 的文档,可以看到如何将附加信息添加到 user.profile。 IE。,

//JS file
Meteor.users.insert({
username: 'admin',
profile: {
first_name: 'Clark',
last_name: 'Kent'
},

});

那么如何在 View 模板中显示配置文件信息?我可以通过 View 和 Web 控制台 ( Meteor.user() ) 访问用户对象,但是我无法访问对象详细信息。

我最初的想法是我可以在我的 Handlebars 模板中加载以下内容,但它们不起作用:
// HTML view
{{Meteor.user().username}}
{{Meteor.user().profile.first_name}}
{{Meteor.user().profile.last_name}}

任何帮助是极大的赞赏。

最佳答案

你的插入是正确的。

但是要显示诸如名字之类的信息,您必须提供一个辅助函数。

您的 html 模板:

<template name="user">
<p>{{firstName}}</p>
</template>

你的js代码:
Template.user.helpers({
firstName: function() {
return Meteor.user().profile.first_name;
}
});

您还可以使用 {{currentUser}} 助手包装用户模板以确保存在用户。
{{#if currentUser}} 
{{> user}}
{{/if}}

关于meteor - 如何在 View 中显示 Meteor.user() 配置文件数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22676470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com